from ._builtin import Page import random class Wait(Page): timeout_seconds = 1 def before_next_page(self): self.player.order = random.randint(1, 2) # self.player.order = self.player.participant.vars.get('order') self.player.similarity = random.randint(1, 2) # self.player.similarity = self.player.participant.vars.get('similarity') self.player.time_pressure = random.randint(1, 2) # self.player.time_pressure = self.player.participant.vars.get('time_pressure') self.player.answer_used = random.randint(1, 2) # self.player.answer_used = self.player.participant.vars.get('answer_used') self.player.recorded_statement = "The United Kingdom should leave the European Union." # self.player.recorded_statement = self.player.participant.vars.get('recorded_statement') self.player.attempt = 0 class Instructions(Page): form_model = 'player' form_fields = ['q1', 'q2', 'q3', 'q4', 'q5', 'q6', 'q7'] def vars_for_template(self): attempts_left = 3 - self.player.attempt return dict( attempts_left=attempts_left ) def before_next_page(self): self.player.attempt = self.player.attempt + 1 self.player.q1_error = False if self.player.q1 != 1: self.player.q1_error = True self.player.q2_error = False if self.player.q2 != 1: self.player.q2_error = True self.player.q3_error = False if self.player.q3 != 2: self.player.q3_error = True self.player.q4_error = False if self.player.q4 != 7.5: self.player.q4_error = True self.player.q5_error = False if self.player.q5 != 7.5: self.player.q5_error = True self.player.q6_error = False if self.player.q6 != 2: self.player.q6_error = True if self.player.time_pressure == 1: self.player.q7_error = False if self.player.q7 != 3: self.player.q7_error = True if self.player.time_pressure == 2: self.player.q7_error = False if self.player.q7 != 2: self.player.q7_error = True self.player.cq_error = False if self.player.q1_error or self.player.q2_error or self.player.q3_error or self.player.q4_error or \ self.player.q5_error or self.player.q6_error or self.player.q7_error: self.player.cq_error = True if self.player.cq_error and self.player.attempt < 3: self._is_frozen = False self._index_in_pages -= 1 self.participant._index_in_pages -= 1 class End(Page): def is_displayed(self): return self.player.cq_error class Congratulations(Page): pass class Information(Page): form_model = 'player' form_fields = ['perceived_similarity'] def before_next_page(self): self.player.participant.vars['perceived_similarity'] = self.player.perceived_similarity page_sequence = [ Wait, Instructions, End, Congratulations, Information ]