from otree.api import * import random doc = """ Welcome page, Akdeniz & Mathew, 2022, "Normative versus prosocial underpinnings of human decision making". """ class Constants(BaseConstants): players_per_group = None num_rounds = 1 name_in_url = 'welcome' number_tasks = 8 class Subsession(BaseSubsession): pass def creating_session(subsession: Subsession): if subsession.round_number == 1: for player in subsession.get_players(): participant = player.participant participant.sequence = random.randint(1, 8) print('sequence is', participant.sequence) player.seq = participant.sequence if (participant.sequence == 1) or (participant.sequence == 3) or (participant.sequence == 5) or (participant.sequence == 7): participant.dg_order = 1 player.dg_seq = 1 else: participant.dg_order = 2 player.dg_seq = 2 print('dg order is', participant.dg_order) if (participant.sequence == 1) or (participant.sequence == 2) or (participant.sequence == 5) or (participant.sequence == 6): participant.dg3pp_order = 1 player.dg3pp_seq = 1 else: participant.dg3pp_order = 2 player.dg3pp_seq = 2 print('dg3pp order is', participant.dg3pp_order) if (participant.sequence == 1) or (participant.sequence == 2) or (participant.sequence == 3) or (participant.sequence == 4): participant.tog_order = 1 player.tog_seq = 1 else: participant.tog_order = 2 player.tog_seq = 2 print('tog order is', participant.tog_order) class Group(BaseGroup): pass class Player(BasePlayer): IbanNo = models.StringField(label="What is your IBAN number?") IbanName = models.StringField(label="What is the account holder's name? (Please make sure to write " "the name as exactly stated on your bank account") seq = models.IntegerField() dg_seq = models.IntegerField() dg3pp_seq = models.IntegerField() tog_seq = models.IntegerField() # FUNCTIONS # PAGES class Welcome(Page): pass class IbanNumber(Page): form_model = 'player' @staticmethod def get_form_fields(self): if self.session.config['country'] == 'tr': return ['IbanNo', 'IbanName'] else: return ['IbanNo'] def vars_for_template(self): return dict( country=self.session.config['country'], ) def error_message(self, value): print('Iban is', value['IbanNo']) print('Iban length is', len(value['IbanNo'])) if len(value['IbanNo']) > 34: return 'IBAN numbers cannot be longer than 34 characters.' elif len(value['IbanNo']) < 10: return 'IBAN numbers cannot be shorter than 10 characters.' class Instructions(Page): def vars_for_template(self): return dict( participation_fee=self.session.config['participation_fee'], currency_per_point=self.session.config['real_world_currency_per_point'], country=self.session.config['country'], ) class Start(Page): pass class PartIIntro(Page): def vars_for_template(self): return dict( country=self.session.config['country'], ) @staticmethod def app_after_this_page(player, upcoming_apps): print('upcoming_apps is', upcoming_apps) participant = player.participant if participant.dg_order == 1: return "part1task1_1" elif participant.dg_order == 2: return "part1task1t_1" page_sequence = [Welcome, IbanNumber, Instructions, Start, PartIIntro]