from otree.api import * doc = """ Your app description """ class C(BaseConstants): NAME_IN_URL = "outro" PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 # Prolific PROLIFIC_COMPLETION_CODE = "#" # TODO: fill with completion code PROLIFIC_URL = "https://app.prolific.co/submissions/complete?cc={}" class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): gender = models.StringField( choices=["Female", "Male", "Other"], widget=widgets.RadioSelect, label="What is your sex?", blank=True ) birthyear = models.IntegerField(min=1920, max=2020, label="What year were you born in?", blank=True) race = models.StringField( choices=[ "Black, African-American", "Native American, Alaskan native", "Latino, Mexican-American, Hispanic", "Asian, Pacific Islander", "White, Caucasian", "Other", ], label="What is your race?", widget=widgets.RadioSelect, blank=True, ) us_citizen = models.BooleanField( label="Are you a U.S. citizen?", choices=[[True, "Yes"], [False, "No"]], widget=widgets.RadioSelect, blank=True ) political_affiliation = models.StringField( label="How would you describe your political affiliation?", choices=["Republican", "Democrat", "Independent", "Other", "Apolitical"], widget=widgets.RadioSelect, blank=True, ) marital_status = models.StringField( label="What is your current marital status?", choices=["Single", "Married", "Divorced", "Widowed"], widget=widgets.RadioSelect, blank=True, ) children = models.IntegerField(label="How many children do you have?", min=0, blank=True) siblings = models.IntegerField(label="How many siblings do you have?", min=0, blank=True) education = models.StringField( widget=widgets.RadioSelect, choices=[ "Some High School", "High School", "Some college", "Bachelor's degree", "Master's degree", "Professional degree", "Doctorate", "Other", ], label="What is the highest level of education you have completed?", blank=True, ) major = models.StringField( widget=widgets.RadioSelect, label="What is/was your major in college?", choices=[ "Technical Studies", "Natural Sciences", "Humanities", "Economics & Business", "Social Sciences", "Other", ], blank=True, ) religious_affiliation = models.StringField( widget=widgets.RadioSelect, label="What is your religious affiliation?", choices=[ "Agnostic", "Atheist", "Buddhist", "Christian", "Hindu", "Jewish", "Muslim", "Other affliciation", "No preference", ], blank=True, ) religion_importance = models.StringField( widget=widgets.RadioSelect, label="Does your religious denomination play an important role in your daily life?", choices=[ "Plays a very important role", "Plays an important role", "Plays a role", "Plays a minor role", "Is of no importance", ], blank=True, ) income = models.StringField( widget=widgets.RadioSelect, label="What is your disposable monthly income?", choices=["Less than $500", "$1000 - $2000", "$2000 - $5000", "More than $5000"], blank=True, ) travel = models.StringField( widget=widgets.RadioSelect, label="How often do you travel outside of your state?", choices=[ "Never", "Hardly ever (less than 1x in 2-3 years)", "Occasionally (1x in 2-3 years)", "Regularly (1x per year)", "Often (more than 1x per year)", ], blank=True, ) employment_status = models.StringField( widget=widgets.RadioSelect, label="What is your employment status?", choices=[ "Full-Time (employed)", "Part-Time (employed)", "Full-Time (self-employed)", "Part-Time (self-employed)", "Due to start a new job within the next month", "Unemployed (and job seeking)", "Not in paid work (e.g. homemaker, retired or disabled)", "Other", ], blank=True, ) risk = models.IntegerField( label="How do you personally assess yourself: Are you generally a person willing to take risks or do you try to avoid risks?", widget=widgets.RadioSelect, choices=[ [-5, ""], [-4, ""], [-3, ""], [-2, ""], [-1, ""], [0, ""], [1, ""], [2, ""], [3, ""], [4, ""], [5, ""], ], blank=True, ) completed = models.BooleanField(initial=False) # PAGES class DisplayPage(Page): @staticmethod def is_displayed(player: Player): return not player.participant.dropout class Demographics1(DisplayPage): form_model = "player" form_fields = [ "gender", "birthyear", "race", "us_citizen", "political_affiliation", "marital_status", "children", "siblings", "education", ] class Demographics2(DisplayPage): form_model = "player" @staticmethod def get_form_fields(player: Player): form_fields = [] education = player.field_maybe_none("education") if education and "High School" not in education: form_fields.append("major") form_fields += ["religious_affiliation", "religion_importance", "income", "travel", "employment_status"] return form_fields class Demographics3(DisplayPage): form_model = "player" form_fields = ["risk"] @staticmethod def before_next_page(player: Player, timeout_happened): player.completed = True class Payment(Page): @staticmethod def vars_for_template(player: Player): return dict( payoff=player.participant.payoff.to_real_world_currency(player.session), prolific_url=C.PROLIFIC_URL.format(player.session.config["completion_code"]), ) page_sequence = [Demographics1, Demographics2, Demographics3, Payment]