from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from django.views.decorators.csrf import csrf_exempt from django.utils.decorators import method_decorator import numpy as np def vars_for_all_templates(self): return { 'radio_amounts': zip(Constants.list2, Constants.list1), 'participation_fee': c(self.session.config['participation_fee']), 'exp_duration': self.session.config['exp_duration'], 'baseline_bonus': c(self.session.config['baseline_bonus']) } @method_decorator(csrf_exempt, name='dispatch') class ProlificID(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['prolific_id'] class Welcome(Page): def is_displayed(self): return self.round_number == 1 class Consent(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = ['consent'] def app_after_this_page(self, upcoming_apps): if not self.player.consent: self.participant.vars['consent'] = False return upcoming_apps[-1] class Instructions(Page): def is_displayed(self): return True class ComprehensionCheck(Page): def is_displayed(self): return self.round_number == 1 form_model = 'player' form_fields = [ 'qn_payoff', 'qn_confidence' ] def qn_payoff_error_message(self, value): if value != 1: self.player.qn_payoff_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True self.player.question_failed = 1 def qn_confidence_error_message(self, value): if value != 15: self.player.qn_confidence_got_wrong = True self.player.failed_comprehension = True self.participant.vars['failed_comprehension'] = True self.player.question_failed = 2 class BeginStudy(Page): def is_displayed(self): return self.player.round_number == 1 and not self.participant.vars['failed_comprehension'] class FailedComprehension(Page): def is_displayed(self): return self.participant.vars['failed_comprehension'] class Wait(Page): def is_displayed(self): return self.round_number == Constants.num_rounds timeout_seconds = 5 page_sequence = [ # ProlificID, Welcome, Instructions, # ComprehensionCheck, # FailedComprehension, BeginStudy, # Consent, # InstructionsPart1, # InstructionsPart2, # ComprehensionCheck, # FailedComprehension, # List, # Valuation, # Wait ]