from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import time import random import json class sona(Page): form_model = 'player' form_fields = ['sona'] class consent(Page): form_model = 'player' class self(Page): form_model = 'player' form_fields = ['initials', 'major', 'food', 'holiday', 'eve', 'goal2020'] timeout_seconds = 60 class instruction1(Page): timeout_seconds = 15 class instruction2(Page): timeout_seconds = 15 class instruction3(Page): timeout_seconds = 10 class instruction4(Page): form_model = 'player' form_fields = ['ac1', 'ac2'] def error_message(self, values): if values['ac1'] + values['ac2'] > 2: return 'Please read the instruction carefully and try to answer the questions again.' def before_next_page(self): import time self.player.min_time = time.time() + 37 class wait(Page): form_model = 'player' def error_message(self, values): if time.time() < self.player.min_time: return 'Please wait patiently while the profiles of the other participants are being generated.' class view(Page): timeout_seconds = 60 class sk(Page): form_model = 'player' def get_form_fields(self): sc = ['sk_sc1', 'sk_sc2'] med = ['sk_assert1', 'sk_assert2', 'sk_assert3', 'sk_assert4', 'sk_auth1', 'sk_auth2', 'sk_auth3', 'sk_warm1', 'sk_warm2', 'sk_warm3', 'sk_warm4', 'sk_warm5', 'sk_comp1', 'sk_comp2', 'sk_comp3', 'sk_comp4', 'sk_comp5', 'sk_moral1', 'sk_moral2', 'sk_moral3', 'sk_moral4', 'sk_moral5'] pow_p = ['sk_pow_p1', 'sk_pow_p2', 'sk_pow_p3', 'sk_pow_p4'] random.shuffle(pow_p) random.shuffle(med) random.shuffle(sc) return sc+med+pow_p class mz(Page): form_model = 'player' def get_form_fields(self): sc = ['mz_sc1', 'mz_sc2'] med = ['mz_assert1', 'mz_assert2', 'mz_assert3', 'mz_assert4', 'mz_auth1', 'mz_auth2', 'mz_auth3', 'mz_warm1', 'mz_warm2', 'mz_warm3', 'mz_warm4', 'mz_warm5', 'mz_comp1', 'mz_comp2', 'mz_comp3', 'mz_comp4', 'mz_comp5', 'mz_moral1', 'mz_moral2', 'mz_moral3', 'mz_moral4', 'mz_moral5'] pow_p = ['mz_pow_p1', 'mz_pow_p2', 'mz_pow_p3', 'mz_pow_p4'] random.shuffle(pow_p) random.shuffle(med) random.shuffle(sc) return sc+med+pow_p class pow_c(Page): form_model = 'player' def get_form_fields(self): profiles = ['sk_vote','mz_vote'] sequences = [] sequences.append(profiles[self.player.page_order]) sequences.append(profiles[1-self.player.page_order]) return sequences def error_message(self,values): if values['mz_vote'] + values['sk_vote'] != 10: return 'Please give 10 votes in total.' #class pow_p(Page): # form_model = 'player' #class sc(Page): # form_model = 'player' class demo(Page): form_model = 'player' form_fields = ['age', 'gender', 'race','native'] class native1(Page): form_model = 'player' form_fields = ['native_lan','native_fluency'] def is_displayed(self): return self.player.native == 0 class native2(Page): form_model = 'player' form_fields = ['native_age'] def is_displayed(self): return self.player.native_fluency == 1 class probe(Page): form_model = 'player' form_fields = ['purpose','suspicion','comment'] class calculate(Page): timeout_seconds = 8 initial_page_sequence = [sona, consent, self, instruction1, instruction2, instruction3, instruction4, wait, view, sk, mz, pow_c, demo, native1, native2, probe, calculate] page_sequence = [] class MyPage(Page): def inner_dispatch(self): page_seq = int(self.__class__.__name__.split('_')[1]) page_to_show = json.loads(self.player.page_sequence)[page_seq] self._is_frozen = False self.__class__ = globals()[page_to_show] return super(globals()[page_to_show], self).inner_dispatch() for i, _ in enumerate(initial_page_sequence): NewClassName = "Page_{}".format(i) A = type(NewClassName, (MyPage,), {}) locals()[NewClassName] = A page_sequence.append(locals()[NewClassName])