from otree.api import * doc = """ Demographic survey — final page of the study. """ class C(BaseConstants): NAME_IN_URL = "demographics" PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): age = models.StringField( label="How old are you?", choices=[ "18-25", "26-30", "31-35", "36-40", "41-45", "46-50", "51-55", "56-60", "61-65", "66-70", "71+", ], widget=widgets.RadioSelect, blank=True ) gender = models.StringField( label="What is your gender?", choices=["Male", "Female", "Prefer not to say"], widget=widgets.RadioSelect, blank=True ) education = models.StringField( label="What is your highest level of education?", choices=[ "High School", "Associate's Degree or Trade School", "Bachelor's Degree", "Graduate Degree (e.g., Masters, Doctorate)", "None of the above", ], widget=widgets.RadioSelect, blank=True ) race = models.StringField( label="What is your race?", choices=[ "White", "Black or African American", "Native American or American Indian", "Asian or Pacific Islander", "Other", ], widget=widgets.RadioSelect, blank=True ) ethnicity = models.StringField( label="Are you of Hispanic or Latino origin?", choices=["Yes", "No"], widget=widgets.RadioSelect, blank=True ) employment = models.StringField( label="What is your current employment status?", choices=[ "Employed", "Self-employed", "Student", "Military", "Retired", "Other", ], widget=widgets.RadioSelect, blank=True ) income = models.StringField( label="What was your total household income before taxes during the past 12 months?", choices=[ "Under $25,000", "$25,001 - $50,000", "$50,001 - $75,000", "$75,001 - $100,000", "$100,000+", ], widget=widgets.RadioSelect, blank=True ) religion = models.StringField( label="Which of the following best describes your religious or spiritual affiliation?", choices=[ "Islam", "Judaism", "Christianity", "Hinduism", "Buddhism", "Sikhism", "Other", "None/Atheist/Agnostic", ], widget=widgets.RadioSelect, blank=True ) politics = models.StringField( label="Which of the following political affiliations best represents your views?", choices=[ "Democrat", "Republican", "Independent", "Libertarian", "Green Party", "Other", "None/I prefer not to say", ], widget=widgets.RadioSelect, blank=True ) class Demographics(Page): form_model = "player" form_fields = [ "age", "gender", "education", "race", "ethnicity", "employment", "income", "religion", "politics", ] @staticmethod def vars_for_template(player: Player): return dict( completionlink=player.session.config["completionlink"], ) @staticmethod def error_message(player: Player, values): demo_fields = [ "age", "gender", "education", "race", "ethnicity", "employment", "income", "religion", "politics", ] for field in demo_fields: if values.get(field) is None or values.get(field) == "": return "Please answer all questions before proceeding." @staticmethod def before_next_page(player: Player, timeout_happened): player.participant.vars["completed"] = True class Redirect(Page): @staticmethod def vars_for_template(player: Player): return dict( completionlink=player.session.config["completionlink"], ) @staticmethod def error_message(player: Player, values): demo_fields = [ "age", "gender", "education", "race", "ethnicity", "employment", "income", "religion", "politics", ] for field in demo_fields: if values.get(field) is None or values.get(field) == "": return "Please answer all of the questions before proceeding." page_sequence = [Demographics, Redirect]