from otree.api import * from .models import C, Player class BasePage(Page): def vars_for_template(self): lang = self.session.config.get('language', 'en') return dict( id=lang == 'id', en=lang == 'en', ) class a_Consent1_Information_Page(BasePage): pass class b_Consent2_Withdrawal_Right(BasePage): form_model = 'player' form_fields = [ 'Consent_Withdrawal_Right', ] def before_next_page(self): p = self.player if not ( p.Consent_Withdrawal_Right ): p.consent_failed = True class c_Consent3_Anonimity_Confidentiality(BasePage): form_model = 'player' form_fields = [ 'Anon_Confid_Anon1', 'Anon_Confid_Anon2', ] def is_displayed(self): player=self.player return player.consent_failed is False def before_next_page(self): p = self.player if not ( p.Anon_Confid_Anon1 and p.Anon_Confid_Anon2 ): p.consent_failed = True class d_Consent4_Contact_Ethics(BasePage): def is_displayed(self): player = self.player return player.consent_failed is False class e_ConsentForm(BasePage): form_model = 'player' form_fields = ['age_18', 'consent_q'] def is_displayed(self): player = self.player return player.consent_failed is False def before_next_page(self): p = self.player if not (p.age_18 and p.consent_q): p.consent_failed = True class f_ExitPage(BasePage): def is_displayed(self): return self.player.consent_failed class ee_Payment_Information(Page): def is_displayed(self): player = self.player return player.consent_failed is False class g_Demographics(BasePage): form_model = 'player' form_fields = ['name', 'age', 'gender', 'phone_number', 'Activity_School', 'Activity_Main', ] @staticmethod def error_message(values): phone = values.get('phone_number', '').strip() if phone and not (phone.startswith('08') or phone.startswith('+62')): return ( 'Please enter a valid Indonesian phone number ' '(starting with 08 or +62).' ) Activity_Main = values.get('Activity_Main', '').strip() Activity_School = values.get('Activity_School', '').strip() if Activity_Main == 'School' and not Activity_School == 'Yes' : return('You choose School/College/University as your main activity in the last week' 'but you answered you are currently not enrolled in a School/College/University' ) def is_displayed(self): player = self.player return player.consent_q and player.age_18 class g2_University(BasePage): form_model = 'player' form_fields = [ 'university', 'lainnya_x', 'field_study', 'faculty', ] def is_displayed(self): player = self.player return ( player.consent_q and player.age_18 and player.Activity_School == 'Yes' ) class h_Family_Friend(BasePage): form_model = 'player' form_fields = ['family_phone', 'family_relation', 'friend_phone', 'gender_friend'] @staticmethod def error_message(values): def is_valid_indo_phone(phone): if not phone: return True # allow blank if not required phone = phone.strip() return phone.startswith('08') or phone.startswith('+62') if not is_valid_indo_phone(values.get('family_phone')): return ( 'Please enter a valid Indonesian family phone number ' '(starting with 08 or +62).' ) if not is_valid_indo_phone(values.get('friend_phone')): return ( 'Please enter a valid Indonesian friend phone number ' '(starting with 08 or +62).' ) class End(BasePage): @staticmethod def is_displayed(player): return True class i_Survey_to_Game(BasePage): pass page_sequence = [ a_Consent1_Information_Page, b_Consent2_Withdrawal_Right, c_Consent3_Anonimity_Confidentiality, d_Consent4_Contact_Ethics, e_ConsentForm, ee_Payment_Information, f_ExitPage, g_Demographics, g2_University, h_Family_Friend, i_Survey_to_Game, ]