from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants import random import itertools class p0_set_cookies(Page): timeout_seconds = 0 def is_displayed(self): return self.round_number == 1 def before_next_page(self): # Save the cookie to be used in case the user disconnects parti_url = self.request.build_absolute_uri( self.player.participant._start_url()) self.request.session["otree"] = parti_url self.request.session.set_expiry( 24 * 60 * 60) # Set the cookie for X hours print('cookie installé pour 24h') class p0_intro(Page): def is_displayed(self): return self.round_number == 1 class p1_politique(Page): form_model = 'player' form_fields = ['p1_politique'] def is_displayed(self): return self.round_number == 1 def before_next_page(self): if (self.player.p1_politique == 'Je ne sais pas'): self.participant.vars['groupe'] = "nsp" self.participant.vars['other_groupe'] = "nsp" # ne sait toujours pas LOL PTDR self.participant.vars['sous_groupe'] = "nstp" elif (int(self.player.p1_politique) <= 5): self.player.polmessage = "Votre réponse indique que vous vous situez à gauche de l'échiquier politique." self.participant.vars['groupe'] = "gauche" self.participant.vars['other_groupe'] = "droite" self.participant.vars['sous_groupe'] = random.choice( Constants.sous_groupes_gauche) elif (int(self.player.p1_politique) > 5): self.player.polmessage = "Votre réponse indique que vous vous situez à droite de l'échiquier politique." self.participant.vars['groupe'] = "droite" self.participant.vars['other_groupe'] = "gauche" self.participant.vars['sous_groupe'] = random.choice( Constants.sous_groupes_droite) self.player.groupe = self.participant.vars['groupe'] self.player.other_groupe = self.participant.vars['other_groupe'] self.player.sous_groupe = self.participant.vars['sous_groupe'] class p2_resultats(Page): def is_displayed(self): return ((self.participant.vars['groupe'] != "nsp") and (self.round_number == 1)) class p3_identification(Page): def is_displayed(self): return ((self.participant.vars['groupe'] != "nsp") and (self.round_number == 1)) form_model = 'player' form_fields = ['self_love', 'self_identification', 'others_love', 'others_identification'] def vars_for_template(self): return dict( self_love_label='J\'apprécie le groupe des personnes de {} :'.format( self.participant.vars['groupe']), others_love_label='J\'apprécie le groupe des personnes de {} :'.format( self.participant.vars['other_groupe']), self_identification_label='Je m\'identifie au groupe des personnes de {} :'.format( self.participant.vars['groupe']), others_identification_label='Je m\'identifie au groupe des personnes de {} :'.format( self.participant.vars['other_groupe']) ) class p4_matrices_consignes(Page): form_model = 'player' form_fields = ['matrix0_response'] def is_displayed(self): return ((self.participant.vars['groupe'] != "nsp") and (self.round_number == 1)) class p5_matrice_1(Page): form_model = 'player' form_fields = ['matrix1_response'] def is_displayed(self): return ((self.participant.vars['groupe'] != "nsp") and (self.round_number == 1)) class p6_matrice_2(Page): form_model = 'player' form_fields = ['matrix2_response'] def is_displayed(self): return ((self.participant.vars['groupe'] != "nsp") and (self.round_number == 1)) class p7_mots(Page): form_model = 'player' def get_form_fields(self): # si on est sur le round_immig if self.participant.vars['round_immig'] == self.round_number: print('on passe dans round immig') return ['immig_mot_1', 'immig_mot_2', 'immig_mot_3'] # si on est sur le round_chomage elif (self.participant.vars['round_chomage'] == self.round_number): print('on passe dans round chomage') return ['chom_mot_1', 'chom_mot_2', 'chom_mot_3'] def vars_for_template(self): # si on est sur le round_immig if (self.participant.vars['round_immig'] == self.round_number): print('on passe dans round immig') return dict( sujet='immigration', mot='immigration', ) # si on est sur le round_chomage elif (self.participant.vars['round_chomage'] == self.round_number): print('on passe dans round chomage') return dict( sujet='chômage', mot='chômeur', ) class p8_eval(Page): form_model = 'player' def get_form_fields(self): if (self.participant.vars['round_immig'] == self.round_number): # si immig en 1 return ['immig_eval_mot_1', 'immig_eval_mot_2', 'immig_eval_mot_3'] # si chom en 1 elif (self.participant.vars['round_chomage'] == self.round_number): return ['chom_eval_mot_1', 'chom_eval_mot_2', 'chom_eval_mot_3'] def vars_for_template(self): # si on est sur le round_immig if (self.participant.vars['round_immig'] == self.round_number): return dict( sujet='immigration', mot='immigration', mot1=self.player.immig_mot_1, mot2=self.player.immig_mot_2, mot3=self.player.immig_mot_3, ) # si on est sur le round_chomage elif (self.participant.vars['round_chomage'] == self.round_number): return dict( sujet='chômage', mot='chômeur', mot1=self.player.chom_mot_1, mot2=self.player.chom_mot_2, mot3=self.player.chom_mot_3, ) class p9_last_questions_ID(Page): form_model = 'player' form_fields = ['sexe', 'age'] def is_displayed(self): return self.round_number == 2 def before_next_page(self): if self.player.sexe != '': # de cette manière ça ne passe que s'il n'y a pas eu de push self.participant.vars['statut'] = 'ok' self.participant.vars['somme_finale'] = Constants.paiement self.player.statut = 'ok' else: self.participant.vars['statut'] = '!! PUSH ' self.participant.vars['somme_finale'] = 0 self.player.statut = '!! PUSH' page_sequence = [ p0_set_cookies, p0_intro, p1_politique, p2_resultats, p3_identification, p4_matrices_consignes, p5_matrice_1, p6_matrice_2, p7_mots, p8_eval, p9_last_questions_ID, ]