from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from captcha.fields import ReCaptchaField import math class Consent(Page): form_model = 'player' form_fields = ['consent'] timeout_seconds = Constants.consent_timeout timeout_submission = {'consent': False} def vars_for_template(self): return {'time': Constants.time, 'redemption_code': Constants.code, 'max_bonus': Constants.max_bonus, 'participation_fee': Constants.participation_fee, 'consent_timeout_min': math.ceil(self.timeout_seconds / 60) } def before_next_page(self): if self.timeout_happened: self.player.consent = False self.player.is_dropout = True self.player.participant.vars['dropout'] = True self.player.participant.vars['consent_dropout'] = True else: self.player.consent = True self.player.is_dropout = False class BlockDropouts(Page): def is_displayed(self): return self.round_number == 1 and self.player.participant.vars.get('consent_dropout', False) class CaptchaPage(Page): _allow_custom_attributes = True form_model = 'player' form_fields = ['captcha'] def get_form(self, data=None, files=None, **kwargs): frm = super().get_form(data, files, **kwargs) frm.fields['captcha'] = ReCaptchaField(label='') return frm class Screening(Page): form_model = 'player' form_fields = ['state', 'yob', 'sex', 'marital_status', 'personal_income', 'race', 'education', 'height_feet', 'height_inches', 'weight', 'attention_check_4july'] def before_next_page(self): self.player.ip = self.request.META['REMOTE_ADDR'] if getattr(self.player, 'yob') > 2000 or getattr(self.player, 'attention_check_4july') > 1: self.player.qualified = False self.player.participant.vars['qualified'] = False else: self.player.qualified = True class BlockNotQualified(Page): def is_displayed(self): return self.player.participant.vars.get('qualified', False) class Instructions(Page): form_model = 'player' def vars_for_template(self): return {'participation_fee': Constants.participation_fee, 'bonus': Constants.bonus, 'max_bonus': Constants.max_bonus, 'n_questions': Constants.n_questions, 'n_sections': Constants.n_sections, 'mturk_completion_code': Constants.code, 'time': Constants.time } page_sequence = [ Consent, BlockDropouts, CaptchaPage, Screening, Instructions ]