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 import time def vars_for_all_templates(self): return { '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 not self.participant.vars['attention_got_wrong'] form_model = 'player' form_fields = ['prolific_id'] class Welcome(Page): def is_displayed(self): return self.round_number == 1 and not self.player.participant.vars['attention_got_wrong'] class Consent(Page): 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 AttentionCheck1(Page): form_model = 'player' form_fields = ['attention1_check'] def before_next_page(self): if "1" not in self.player.attention1_check or "5" not in self.player.attention1_check or "2" in self.player.attention1_check or "3" in self.player.attention1_check or "4" in self.player.attention1_check: self.player.attention_got_wrong = True self.player.participant.vars['attention_got_wrong'] = True class AttentionCheck2(Page): def is_displayed(self): return not self.player.participant.vars['attention_got_wrong'] form_model = 'player' form_fields = ['attention2_check'] def before_next_page(self): length_attention_check2 = 0 if self.player.attention2_check is not None: length_attention_check2 = len(self.player.attention2_check.split()) if self.player.attention2_check is None or length_attention_check2 < 15: self.player.attention_got_wrong = True self.player.participant.vars['attention_got_wrong'] = True class FailedAttention(Page): def is_displayed(self): return self.participant.vars['attention_got_wrong'] page_sequence = [ # AttentionCheck2, # FailedAttention, # ProlificID, Welcome ]