from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import json # Now define a function to get the randomized order for the pages D, E, F, G def get_randomized_pages(player): return player.participant.vars['randomized_pages'] class new_step(Page): pass class p1_consigne(Page): pass class choix_asso(Page): form_model = 'player' form_fields = ['association_choice'] def vars_for_template(self): return { 'associations': self.participant.vars['associations'] } def before_next_page(self): self.player.association_choice = self.request.POST.get('association_choice') self.player.chosen_asso() class new_step2(Page): pass class p2_consigne_normalisation(Page): pass # NORMALISATION DE Y class normalization_y(Page): form_model = 'player' def get_form_fields(self): return [f'choice_y_{i}' for i in range(1, len(Constants.y_values) + 1)] def vars_for_template(self): options = [] for i, x in enumerate(Constants.y_values, start=1): option_a = str(self.participant.vars['y_me'])+'€' option_b = f"{x}€" options.append((i, option_a, option_b)) return {'options': options} def before_next_page(self): # Récupère les valeurs de choix du joueur et les traite ou les affiche comme nécessaire self.player.get_choice_values_y() self.player.min_choice_value_y() # NORMALISATION DE X class normalization_x(Page): form_model = 'player' def get_form_fields(self): return [f'choice_x_{i}' for i in range(1, len(Constants.x_values) + 1)] def vars_for_template(self): # Préparez les options pour le template options = [] for i, x in enumerate(Constants.x_values, start=1): option_a = str(self.participant.vars['x_me'])+'€' option_b = f"{x}€" options.append((i, option_a, option_b)) return {'options': options} def before_next_page(self): # Récupérez les valeurs de choix du joueur pour x et traitez-les self.player.get_choice_values_x() self.player.min_choice_value_x() class fin_maif_asso(Page): def vars_for_template(self): self.player.corrector_def() self.player.y_norm_computed_def() class consigne_générale_prev(Page): pass initial_page_sequence = [new_step, p1_consigne, choix_asso, new_step2, p2_consigne_normalisation, normalization_y, normalization_x, fin_maif_asso, consigne_générale_prev] 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])