from otree.api import * import re doc = """ This application provides a webpage instructing participants how to get paid. Examples are given for the lab and Amazon Mechanical Turk (AMT). """ class C(BaseConstants): NAME_IN_URL = 'payment_info' PLAYERS_PER_GROUP = None NUM_ROUNDS = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): mailwin = models.StringField( label = 'Wenn Sie dies möchten, tragen Sie bitte hier ihre Email-Adresse ein:', blank = True ) mailpanel = models.StringField( label = 'Dann tragen Sie bitte hier ihre Email-Adresse ein:', blank = True ) consentwin = models.BooleanField(blank = True) consentpanel = models.BooleanField(blank=True) @property def progress(self): return round((self.participant._index_in_pages / self.participant._max_page_index) * 100) # FUNCTIONS # PAGES class PaymentInfo(Page): @staticmethod def vars_for_template(player: Player): participant = player.participant return dict(redemption_code=participant.label or participant.code) form_model = 'player' form_fields = ['mailwin', 'consentwin', 'mailpanel', 'consentpanel'] @staticmethod def error_message(player: Player, values): if values['consentwin']: if not values['mailwin']: return 'Bitte tragen Sie unten Ihre Email-Adresse ein, wenn Sie Ihr Einverständnis geben.' pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b' if(not re.fullmatch(pattern, values['mailwin'])): return 'Bitte tragen Sie nur gültige Email-Adressen ein.' if values['consentpanel']: if not values['mailpanel']: return 'Bitte tragen Sie unten Ihre Email-Adresse ein, wenn Sie Ihr Einverständnis geben.' pattern = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b' if(not re.fullmatch(pattern, values['mailpanel'])): return 'Bitte tragen Sie nur gültige Email-Adressen ein.' class Ende(Page): form_model='player' form_fields = [] page_sequence = [PaymentInfo, Ende]