from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random class Instructions(Page): def vars_for_template(self): showupfee = self.session.config['participation_fee'] max_bonus = self.session.config['max_bonus'] if self.player.cp_error: return {'message': 'Please, re-read the instructions!', 'showupfee': showupfee, 'max_bonus': max_bonus} else: return {'showupfee': showupfee, 'max_bonus': max_bonus} class UQ(Page): form_model = 'player' form_fields = ['uq1', 'uq2', 'uq3'] # Function to redirect to instructions page if the comprehension answers are wrong: def before_next_page(self): p = self.player p.cp_error = False for k, v in Constants.correct_answers.items(): if getattr(p, k) != v: p.cp_error = True break if p.cp_error: for f in self.form_fields: setattr(p, f, None) self._is_frozen = False self._index_in_pages -= 2 self.participant._index_in_pages -= 2 class Beliefs(Page): form_model = 'player' random.seed(11235) def get_form_fields(self): all_fields = ['b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8'] random.shuffle(all_fields) return all_fields def vars_for_template(self): image = self.participant.vars['images'] return {'img_to_show': image} class Perception(Page): form_model = 'player' random.seed(11235) def get_form_fields(self): all_fields = ['q1', 'q2', 'q3', 'q4', 'q5', 'q6', 'q7', 'q8'] random.shuffle(all_fields) return all_fields def vars_for_template(self): image = self.participant.vars['images'] return {'img_to_show': image} class ResultsWaitPage(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() class Payments(Page): pass page_sequence = [ Instructions, UQ, Beliefs, Perception, ResultsWaitPage, ]