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 def vars_for_all_templates(self): num_rounds = Constants.num_rounds return { 'radio_amounts': zip(Constants.list2, Constants.list1), 'round': self.round_number, 'num_questions': num_rounds, 'time_limit': 10, 'timeout_cost': self.session.config['timeout_penalty'], } @method_decorator(csrf_exempt, name='dispatch') class IntroElicitation(Page): def is_displayed(self): return self.player.round_number == 1 and self.participant.vars['tests_passed'] def before_next_page(self): self.player.tests_passed = self.participant.vars['tests_passed'] class ElicitList(Page): def is_displayed(self): return self.participant.vars['tests_passed'] and self.player.load_identifier != 1 form_model = 'player' form_fields = ['switching_point'] class ElicitValuation(Page): def is_displayed(self): return self.participant.vars['tests_passed'] form_model = 'player' form_fields = ['confidence'] def vars_for_template(self): return { 'val_up': self.player.switching_point + 1, 'val_low': self.player.switching_point - 1, 'val_up2': self.player.switching_point + 2, 'val_low2': self.player.switching_point - 2, } def before_next_page(self): if self.player.load_identifier != 1: self.player.load_num_correct = self.participant.vars['load_num_correct'] class HeadsUpCounting(Page): def is_displayed(self): return self.participant.vars['tests_passed'] class ElicitListLoad(Page): def is_displayed(self): return self.participant.vars['tests_passed'] and self.player.load_identifier == 1 form_model = 'player' form_fields = ['switching_point', 'load_sum', 'timeout_load'] class LoadSumEntry(Page): def is_displayed(self): return self.participant.vars['tests_passed'] and self.player.load_identifier == 1 form_model = 'player' form_fields = ['load_guess'] def before_next_page(self): if self.player.load_guess == self.player.load_sum: self.player.load_correct = 1 else: self.player.load_correct = 0 self.player.load_num_correct = self.participant.vars['load_num_correct'] + self.player.load_correct self.participant.vars['load_num_correct'] = self.player.load_num_correct class Timeout(Page): def is_displayed(self): return self.participant.vars['tests_passed'] and self.player.timeout_load == 1 def before_next_page(self): self.player.timeout_once = True self.participant.vars['timeout_once'] = self.player.timeout_once page_sequence = [ IntroElicitation, HeadsUpCounting, ElicitList, ElicitListLoad, ElicitValuation, LoadSumEntry, Timeout, ]