from otree.api import * doc = """ foo" """ class C(BaseConstants): NAME_IN_URL = 'Welcome_to_the_Experiment' PLAYERS_PER_GROUP = None INSTRUCTIONS_TEMPLATE = 'WelcomePage1/InstructionPartI.html' Example_TEMPLATE = 'WelcomePage1/InstructionPartIExample.html' NUM_ROUNDS = 1 token_i = 100 TOKEN = 100 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # Step 2 Manually setting up Prolific Link prolific_id = models.StringField(default=str(" ")) prolific_id_w = models.StringField( blank=False, # default=str(" "), verbose_name="Please enter your Prolific ID in the box below and start the experiment." ) # to let the participants go back to instruction page if they didnt fell confident to continue. num_failed_attempts = models.IntegerField(initial=0) failed_too_many = models.BooleanField(initial=False) ### Calculate payoff, which is zero for the survey ### def set_payoff(self): self.payoff = 0 # Make sure they have understood the tasks q_sure = models.CharField(initial=None, choices=['Yes', 'No'], widget=widgets.RadioSelect(), verbose_name='Do you feel confident what you should do in every task?', ) unsure = models.BooleanField(initial=False) # Consent q_consent = models.CharField(initial=None, choices=['I consent', 'I do not consent'], widget=widgets.RadioSelect(), verbose_name=' ', ) no_consent = models.BooleanField(initial=False) # PAGES # Instruction class Welcome(Page): form_model = 'player' form_fields = ['q_consent'] @staticmethod def error_message(player: Player, values): # alternatively, you could make quiz1_error_message, quiz2_error_message, etc. # but if you have many similar fields, this is more efficient. if values["q_consent"] != 'I consent': player.no_consent = True # return errors # @staticmethod # def before_next_page(self, timeout_happened): # self.prolific_id = self.participant.label class NoConsentExit(Page): @staticmethod def is_displayed(player: Player): return player.no_consent class InstructionPartIView(Page): pass class InstructionPartIExampleView(Page): pass class MakeSure(Page): form_model = 'player' form_fields = ['q_sure'] @staticmethod def vars_for_template(player: Player): return dict( attempt=player.num_failed_attempts ) @staticmethod def error_message(player: Player, values): # alternatively, you could make quiz1_error_message, quiz2_error_message, etc. # but if you have many similar fields, this is more efficient. solutions = dict(q_sure='Yes') # error_message can return a dict whose keys are field names and whose # values are error messages errors = {f: 'Please review the instructions.' for f in solutions if values[f] != solutions[f]} # print('errors is', errors) # if values["q_sure"] != 'Yes': # player.unsure = True if errors: player.num_failed_attempts += 1 if player.num_failed_attempts >= 3: player.unsure = True # we don't return any error here; just let the user proceed to the # next page, but the next page is the 'failed' page that boots them # from the experiment. else: return errors class UnsureExit(Page): @staticmethod def is_displayed(player: Player): return player.unsure class AboutCharities(Page): form_model = 'player' form_fields = ['prolific_id_w'] # Step 3 Manually setting up Prolific Link @staticmethod def before_next_page(self, timeout_happened): self.prolific_id = self.participant.label page_sequence = [Welcome, NoConsentExit, InstructionPartIView, InstructionPartIExampleView, MakeSure, UnsureExit, AboutCharities ]