from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from django.conf import settings from captcha.fields import ReCaptchaField class P1(Page): _allow_custom_attributes = True form_model = 'player' form_fields = ['confirmation', 'comprehension'] def get_form(self, data=None, files=None, **kwargs): frm = super().get_form(data, files, **kwargs) frm.fields['captcha'] = ReCaptchaField() return frm def error_message(self, value): if value['confirmation'] != 1: return 'Please read the instructions and confirm by clicking the checkbox below!' def vars_for_template(self): return { 'participation_fee_in_points': Constants.participation_fee_in_points } def is_displayed(self): return self.round_number == Constants.pre_crt_rounds class P1b(Page): def is_displayed(self): return self.round_number == Constants.num_rounds and self.player.in_round(1).comprehension != "30" class P2a(Page): form_model = 'player' form_fields = ['crt_submitted_answer'] # def get_form_fields(self): # return [Constants.crt_questions[self.round_number - 1]] def vars_for_template(self): return { 'image_path': 'po_ca_eb_1/crt/{}.png'.format(self.round_number), 'current_crt': self.round_number } def is_displayed(self): return Constants.pre_crt_rounds <= self.round_number <= Constants.num_crt_rounds and self.player.in_round(1).comprehension == "30" def before_next_page(self): self.player.crt_check_correct() class P2b(Page): form_model = 'player' form_fields = ['crt_familiarity_bat', 'crt_familiarity_widget', 'crt_familiarity_lake', 'crt_familiarity_elves', 'crt_familiarity_marks', 'crt_familiarity_medals', ] def is_displayed(self): return self.round_number == Constants.num_crt_rounds and self.player.in_round(1).comprehension == "30" # def before_next_page(self): # self.player.set_correct_answers_crt() class P3a(Page): def is_displayed(self): return self.round_number == Constants.pre_raven_rounds and self.player.in_round(1).comprehension == "30" def vars_for_template(self): return { 'image_path': 'po_ca_eb_1/ravens/13.png' } class P3b_6(Page): form_model = 'player' form_fields = ['raven_6_submitted_answer'] def is_displayed(self): return Constants.pre_raven_rounds < self.round_number <= Constants.pre_raven_rounds + Constants.num_raven_6_rounds and self.player.in_round(1).comprehension == "30" def before_next_page(self): self.player.raven_6_check_correct() def vars_for_template(self): return { 'image_path': 'po_ca_eb_1/ravens/{}.png'.format( 2*(self.round_number - Constants.num_crt_rounds + 1) + 10), 'current_matrix': self.round_number - Constants.num_crt_rounds } class P3b_8(Page): form_model = 'player' form_fields = ['raven_8_submitted_answer'] def is_displayed(self): return Constants.pre_raven_rounds + Constants.num_raven_6_rounds < self.round_number <= Constants.num_rounds and self.player.in_round(1).comprehension == "30" def before_next_page(self): self.player.raven_8_check_correct() def vars_for_template(self): return { 'image_path': 'po_ca_eb_1/ravens/{}.png'.format( 2*self.round_number), # self.round_number - Constants.num_crt_rounds - Constants.num_raven_6_rounds + 60 - Constants.num_raven_8_rounds 'current_matrix': self.round_number - Constants.num_crt_rounds } class P4(Page): form_model = 'player' form_fields = ['information_results'] def vars_for_template(self): return { 'crt_questions_correct': sum([p.crt_is_correct for p in self.player.in_rounds(Constants.pre_crt_rounds, Constants.num_crt_rounds)]), 'raven_questions_correct': sum([p.raven_is_correct for p in self.player.in_rounds(Constants.num_crt_rounds + 1, Constants.num_rounds)]), 'your_participation_number': self.player.participation_number } def is_displayed(self): return self.round_number == Constants.num_rounds and self.player.in_round(1).comprehension == "30" page_sequence = [ P1, P1b, P2a, P2b, P3a, P3b_6, P3b_8, P4 ]