from otree.api import * doc = """ Demographics and debriefing """ class C(BaseConstants): NAME_IN_URL = 'questionnaire' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 PRIVACY_TEMPLATE = 'onboarding/privacy.html' class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): completed_survey = models.BooleanField(initial=False, blank=True) survey_link_clicked = models.BooleanField(initial=False, blank=True) age = models.IntegerField( label="Please enter your age", min=18, max=99, ) gender = models.IntegerField( label="Please select your gender.", choices=[ [1, "Female"], [2, "Male"], [3, "Other"], [4, "Prefer not to say"], ], ) ethnicity = models.IntegerField( label="Which of the following best describes your racial or ethnic background?", blank=False, widget=widgets.RadioSelect, choices=[ [1, "White"], [2, "Black or African American"], [3, "Hispanic or Latino"], [4, "Asian"], [5, "American Indian or Alaska Native"], [6, "Native Hawaiian or Other Pacific Islander"], [7, "Multiracial"], [8, "Other"], [9, "Prefer not to say"], ], ) class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender', 'ethnicity'] @staticmethod def before_next_page(player, timeout_happened): player.completed_survey = True player.participant.finished = True class Debriefing(Page): @staticmethod def live_method(player, data): if data.get('type') == 'survey_clicked': player.survey_link_clicked = True page_sequence = [Demographics, Debriefing]