import random from otree.api import * doc = """ Your app description """ class Constants(BaseConstants): name_in_url = 'treatment_1' players_per_group = None tasks = ['D', 'T', 'P', 'DE'] num_rounds = len(tasks) class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): tax_1 = models.IntegerField( label = 'A jogszabályok lehetővé teszik az ügyeskedést', choices = [1, 2, 3, 4, 5 ], widget = widgets.RadioSelectHorizontal ) tax_2 = models.IntegerField( label = 'Aki csalni akar, mindenképpen megtalálja a módját', choices = [1, 2, 3, 4, 5 ], widget=widgets.RadioSelectHorizontal ) dic = models.IntegerField( label = 'Kérjük, válasszon a legördülő lista percmennyiségei közül!', choices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40 ] ) # FUNCTIONS def creating_session(subsession: Subsession): if subsession.round_number == 1: for p in subsession.get_players(): round_numbers = list(range(1, Constants.num_rounds + 1)) random.shuffle(round_numbers) task_rounds = dict(zip(Constants.tasks, round_numbers)) # print('player', p.id_in_subsession) # print('task_rounds is', task_rounds) p.participant.task_rounds = task_rounds # PAGES class DictatorGame(Page): form_model = 'player' form_fields = ['dic'] @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['D'] class TaxQuestions(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['T'] @staticmethod def get_form_fields(player: Player): import random form_fields = ['tax_1', 'tax_2'] random.shuffle(form_fields) return form_fields class WelcomePage(Page): form_model = 'player' class PsychometricQuestions(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['P'] class DemographicQuestions(Page): form_model = 'player' @staticmethod def is_displayed(player: Player): participant = player.participant return player.round_number == participant.task_rounds['DE'] page_sequence = [WelcomePage, TaxQuestions, DictatorGame, PsychometricQuestions, DemographicQuestions]