import random from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = 'welcome_app_principals' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 # participation payment FIXED_PAY = cu(4) AVG_BONUS_PAY = cu(3.5) MAX_BONUS_PAY = cu(4.5) MAX_TOTAL_PAY = cu(4) + cu(4.5) RACES = [ dict(name='white', label="White"), dict(name='black', label="Black or African American"), dict(name='latino', label="Hispanic, Latino, or Spanish origin"), dict(name='native', label="American Indian or Alaska Native"), dict(name='asian', label="Asian"), dict(name='islander', label="Native Hawaiian or Pacific Islander"), dict(name='middle_east', label="Middle Eastern or North African"), dict(name='other', label="Other"), ] class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): # Prolific_id = models.StringField(label='What is your Prolific ID? Please copy and paste, and avoid typos') age = models.IntegerField(label='What is your age?', min=18, max=99) gender = models.IntegerField( choices=[[0, 'Male'], [1, 'Female'], [1, 'Other']], label='What is your gender?', widget=widgets.RadioSelect, ) education = models.IntegerField( choices=[[1, 'Some high school or less'], [2, 'High school diploma or GED'], [3, 'Some college but no degree'], [4, 'Associates or technical degree'], [5, 'Bachelor degree'], [6, 'Master degree (MA, MS, MENG, MSW, etc)'], [7, 'Professional school degree (MD, DDC, JD, etc)'], [8, 'PhD Degree (PhD, EdD, etc) '], [9, 'Other']], label='What is the highest level of education you have completed?', widget=widgets.RadioSelect, ) white = models.BooleanField(blank=True) black = models.BooleanField(blank=True) latino = models.BooleanField(blank=True) native = models.BooleanField(blank=True) asian = models.BooleanField(blank=True) islander = models.BooleanField(blank=True) middle_east = models.BooleanField(blank=True) other = models.BooleanField(blank=True) # race = models.IntegerField( # choices=[[1, 'White'], [2, 'Black or African American'], [3, 'Hispanic, Latino, or Spanish origin'], # [4, 'American Indian or Alaska Native'], [5, 'Asian'], # [6, 'Native Hawaiian or Pacific Islander'], [7, 'Middle Eastern or North African'], # [8, 'Other']], # label='What is your race?', # widget=widgets.RadioSelect, # ) mothertongue = models.IntegerField( choices=[[1, 'Yes'], [0, 'No']], label='Is English your mother tongue?', widget=widgets.RadioSelect, ) # PAGES class Welcomepage(Page): @staticmethod def vars_for_template(player: Player): return dict( fixed_pay=C.FIXED_PAY, max_bonus_pay=C.MAX_BONUS_PAY, max_total_pay=C.MAX_TOTAL_PAY, ) class Demographics(Page): form_model = 'player' # form_fields = ['Prolific_id', 'age', 'gender', 'education', 'mothertongue'] @staticmethod def get_form_fields(player: Player): # return ['Prolific_id', 'age', 'gender', 'education', 'mothertongue'] + [race['name'] for race in C.RACES] return ['age', 'gender', 'education', 'mothertongue'] + [race['name'] for race in C.RACES] class Instructions_overall(Page): pass class Role(Page): pass class Instructions_for_task1(Page): @staticmethod def app_after_this_page(player, upcoming_apps): print('upcoming_apps is', upcoming_apps) if player.participant.treatment == 'Afirst': return "instructions1_principals" else: return "instructions2_principals" page_sequence = [Welcomepage, Demographics, Instructions_overall, Role, Instructions_for_task1]