from otree.api import * from common_modules import functions as fun class Constants(BaseConstants): name_in_url = 'demographics' players_per_group = None num_rounds = 1 def creating_session(subsession): # Initializing parameters in subsessions: if subsession.round_number == 1: # Initializing or updating "message" of each participant for player in subsession.get_players(): # We must check that message is a key in participant.vars fun.initialize_var_as_dict(player.participant.vars, 'message', 'demographics') class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): age = models.IntegerField(label='¿Qué edad tienes?', min=13, max=125, blank = True) gender = models.StringField( choices=[['M', 'Hombre'], ['F', 'Mujer'], ['N', 'No binario']], label='¿Cuál es tu género?', widget=widgets.RadioSelect, blank = True ) grado = models.StringField( choices=[['ADE', 'ADE'], ['DADE', 'DADE'], ['TADE', 'TADE'], ['I2ADE', 'I2ADE'], ['ECO', 'Economía'], ['MKT', 'Marketing']], label='¿Cuál es tu titulación?', blank = True ) grupo = models.StringField( choices=[['1', '1'], ['2', '2'], ['20', '20'], ['3', '3'], ['30', '30'], ['4', '4'], ['40', '40'], ['5', '5'], ['51', '51'], ['52', '52'], ['6', '6'], ['7', '7'], ['77', '77'], ['8', '8']], label='¿Cuál es tu grupo?', blank = True ) absent = models.BooleanField(initial=True) def custom_export(players): # header row yield ['session', 'participant_code', 'id_in_group', 'age', 'gender', 'grado', 'grupo', 'absent'] for p in players: participant = p.participant session = p.session yield [session.code, participant.code, p.id_in_group, p.age, p.gender, p.grado, p.grupo, p.absent] # FUNCTIONS # PAGES class Demographics(Page): form_model = 'player' form_fields = ['age', 'gender', 'grado', 'grupo'] @staticmethod def error_message(player, values): player.participant.message['demographics']['answers'] = values @staticmethod def before_next_page(player, timeout_happened): # The player is absent if he did not fill in any field. This can be useful info for forthcoming apps if (fun.not_none_or_empty_str(player, 'age') or fun.not_none_or_empty_str(player, 'gender') or fun.not_none_or_empty_str(player, 'grado') or fun.not_none_or_empty_str(player, 'grupo')): player.absent = False else: player.absent = True player.participant.message['demographics']['absent'] = player.absent page_sequence = [Demographics]