from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants from django.apps import apps import random import math import re from datetime import datetime class einleitungstext(Page): template_name = 'bedarfsgerechtigkeit/einleitungstext.html' def is_displayed(self): return True def before_next_page(self): self.player.time_started = datetime.utcnow() class verteilfrage(Page): form_model = 'player' form_fields = ['verteilfrage'] class zustimmung(Page): form_model = 'player' def get_form_fields(self): return ('zustimmungStaat{}'.format(self.player.participant.vars['staat'][0]), 'zustimmungStaat{}'.format(self.player.participant.vars['staat'][1]), 'zustimmungStaat{}'.format(self.player.participant.vars['staat'][2]), 'zustimmungStaat{}'.format(self.player.participant.vars['staat'][3]), 'zustimmungStaat{}'.format(self.player.participant.vars['staat'][4]), 'zustimmungStaat{}'.format(self.player.participant.vars['staat'][5]),) def vars_for_template(self): return { 'questions': self.player.participant.vars['staat'], } page_sequence = [einleitungstext, zustimmung, verteilfrage] # Treatment 1 class monoeinleitung(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class monostich(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class monofragen(Page): form_model = 'player' def get_form_fields(self): return self.player.get_tuple_of_mono_form_fields('') def before_next_page(self): self.player.participant.vars['num_question_mono'] = 1 def vars_for_template(self): return { 'question_data': self.player.get_question_data_mono_as_list(), } def is_displayed(self): return self.player.display_if_treatment_1_or_4() class monosicherheit(Page): form_model = 'player' def get_form_fields(self): return self.player.get_tuple_of_mono_form_fields('Sicher') def vars_for_template(self): return { 'question_data': self.player.get_question_data_mono_as_list(), } def is_displayed(self): return self.player.display_if_treatment_1_or_4() class monofrei(Page): form_model = 'player' form_fields = ['monofrei'] def is_displayed(self): return self.player.display_if_treatment_1_or_4() class seneinleitung(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class senstich(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class sen(Page): form_model = 'player' def get_form_fields(self): return ['Sen{}'.format(self.player.participant.vars['situation_id_sen']),] def is_displayed(self): return self.player.display_if_treatment_1_or_4() def vars_for_template(self): question_data = self.participant.vars['questions_sen'][self.player.participant.vars['num_question_sen'] - 1] return { 'treatment_nummer': self.player.treatment_number, 'frage_nummer': self.player.participant.vars['num_question_sen'], 'question_data': question_data } def before_next_page(self): post_dict = self.request.POST value_sen = post_dict.get('Sen{}'.format(int(self.player.participant.vars['situation_id_sen'])), ) self.player.participant.vars['value_sen'] = value_sen class senvalue(Page): form_model = 'player' def get_form_fields(self): return ['Sen{}value'.format(self.player.participant.vars['situation_id_sen']),] def is_displayed(self): return self.player.display_if_treatment_1_or_4() and int(self.player.participant.vars['value_sen']) != 3 def vars_for_template(self): question_data = self.participant.vars['questions_sen'][self.player.participant.vars['num_question_sen'] - 1] return { 'treatment_nummer': self.player.treatment_number, 'value_sen': self.player.participant.vars['value_sen'], 'frage_nummer': self.player.participant.vars['num_question_sen'], 'question_data': question_data } class sensicher(Page): form_model = 'player' def get_form_fields(self): return 'Sen{}sicher'.format(self.player.participant.vars['situation_id_sen']), def is_displayed(self): return self.player.display_if_treatment_1_or_4() def before_next_page(self): self.player.reihenfolge_sen += 'sen{} '.format(self.player.participant.vars['situation_id_sen']) if self.player.participant.vars['num_question_sen'] != Constants.num_total_questions_sen: self.player.participant.vars['num_question_sen'] += 1 self.player.participant.vars['situation_id_sen'] = self.player.current_question_sen()['situation_id'] class senfrei(Page): form_model = 'player' form_fields = ['senfrei'] def is_displayed(self): return self.player.display_if_treatment_1_or_4() class ueberuntereinleitung(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class ueberunterstich(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class ueberunteruebersicht(Page): def vars_for_template(self): return { 'list_of_question_data': self.player.get_question_data_ueberunter_as_list() } def is_displayed(self): return self.player.display_if_treatment_1_or_4() class ueberunterfragen(Page): form_model = 'player' def get_form_fields(self): return ('{}ueberunter1'.format(self.player.participant.vars['situation_id_ueberunter']), '{}ueberunter2'.format(self.player.participant.vars['situation_id_ueberunter'])) def is_displayed(self): return self.player.display_if_treatment_1_or_4() def vars_for_template(self): return { 'treatment_nummer': self.player.treatment_number, 'frage_nummer': self.player.participant.vars['num_question_ueberunter'], 'question_data': self.player.current_question_ueberunter(), } class ueberuntersicher(Page): form_model = 'player' def get_form_fields(self): return ('{}ueberuntersicher1'.format(self.player.participant.vars['situation_id_ueberunter']), '{}ueberuntersicher2'.format(self.player.participant.vars['situation_id_ueberunter']),) def vars_for_template(self): return { 'question_data': self.player.current_question_ueberunter() } def is_displayed(self): return self.player.display_if_treatment_1_or_4() def before_next_page(self): self.player.reihenfolge_ueberunter += 'ueberunter{} '.format( self.player.participant.vars['situation_id_ueberunter']) if self.player.participant.vars['num_question_ueberunter'] != Constants.num_total_questions_ueberunter: self.participant.vars['num_question_ueberunter'] += 1 self.player.participant.vars['situation_id_ueberunter'] = self.player.current_question_ueberunter()['situation_id'] class ueberunterfrei(Page): form_model = 'player' form_fields = ['ueberunterfrei'] def is_displayed(self): return self.player.display_if_treatment_1_or_4() class skatranseinleitung1(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class skatransstich1(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class skatransfragen1(Page): form_model = 'player' def get_form_fields(self): return self.player.get_tuple_of_skatrans_form_fields('1') def vars_for_template(self): return { 'question_data': self.player.get_question_data_skatrans_as_list('1') } def is_displayed(self): return self.player.display_if_treatment_1_or_4() class skatranseinleitung2(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class skatransstich2(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class skatransfragen2(Page): form_model = 'player' def get_form_fields(self): return self.player.get_tuple_of_skatrans_form_fields('2') def vars_for_template(self): return { 'question_data': self.player.get_question_data_skatrans_as_list('2') } def is_displayed(self): return self.player.display_if_treatment_1_or_4() class skatransfrei(Page): form_model = 'player' form_fields = ['skatransfrei'] def is_displayed(self): return self.player.display_if_treatment_1_or_4() class verteileinleitung(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class verteilstich(Page): def is_displayed(self): return self.player.display_if_treatment_1_or_4() class verteil(Page): form_model = 'player' def get_form_fields(self): return ('{}verteil1'.format(self.player.participant.vars['situation_id_verteil']), '{}verteil2'.format(self.player.participant.vars['situation_id_verteil'])) def is_displayed(self): return self.player.display_if_treatment_1_or_4() def error_message(self, values): question_data = self.participant.vars['questions_verteil'][ self.player.participant.vars['num_question_verteil'] - 1] allocation = question_data['allocation'] if values["{}verteil1".format(question_data['situation_id'])] + values[ "{}verteil2".format(question_data['situation_id'])] > int(allocation): return 'Die Summe beider Eingaben darf ' + allocation + ' nicht übersteigen.' def vars_for_template(self): question_data = self.participant.vars['questions_verteil'][ self.player.participant.vars['num_question_verteil'] - 1] return { 'situation_id': question_data['situation_id'], 'allocation': question_data['allocation'], 'household_A_need': question_data['household_A_need'], 'household_B_need': question_data['household_B_need'], 'verteil1': "#id_{}verteil1".format(question_data['situation_id']), 'verteil2': "#id_{}verteil2".format(question_data['situation_id']), } def before_next_page(self): self.player.reihenfolge_verteil += 'verteil{} '.format(self.player.participant.vars['situation_id_verteil']) if self.player.participant.vars['num_question_verteil'] != Constants.num_total_questions_verteil: self.player.participant.vars['num_question_verteil'] += 1 self.player.question_data_verteil = self.player.current_question_verteil() self.player.participant.vars['situation_id_verteil'] = self.player.question_data_verteil['situation_id'] class verteilfrei(Page): form_model = 'player' form_fields = ['verteilfrei'] def is_displayed(self): return self.player.display_if_treatment_1_or_4() # Treatment 2+3 class auseinleitung(Page): def is_displayed(self): return self.player.display_if_treatment_2_or_3() class ausstich(Page): def is_displayed(self): return self.player.display_if_treatment_2_or_3() page_sequence.extend([auseinleitung, ausstich]) class ausfragen(Page): form_model = 'player' def get_form_fields(self): return ('aus{}frage'.format(self.player.participant.vars['situation_id_aus']),) def is_displayed(self): return self.player.display_if_treatment_2_or_3() def vars_for_template(self): return { 'situation_id': self.player.participant.vars['situation_id_aus'], 'treatment_number': self.player.treatment_number, 'question_number': self.player.participant.vars['num_question_aus'], 'question_data': self.participant.vars['questions_aus'][ self.player.participant.vars['num_question_aus'] - 1], } def before_next_page(self): self.player.reihenfolge_aus += 'aus{} '.format(self.player.participant.vars['situation_id_aus']) if self.player.participant.vars['num_question_aus'] != Constants.num_total_questions_aus: self.player.participant.vars['num_question_aus'] += 1 self.player.participant.vars['situation_id_aus'] = self.participant.vars['questions_aus'][ self.player.participant.vars['num_question_aus'] - 1]['situation_id'] class ausfrei(Page): form_model = 'player' form_fields = ['ausfrei'] def is_displayed(self): return self.player.display_if_treatment_2_or_3() class eineinleitung(Page): def is_displayed(self): return self.player.display_if_treatment_2_or_3() class einstich(Page): def is_displayed(self): return self.player.display_if_treatment_2_or_3() class einuebersicht(Page): def is_displayed(self): return self.player.display_if_treatment_2_or_3() def vars_for_template(self): if self.participant.vars['num_uebersicht'] == 0: question_data = self.participant.vars['questions_ein'][0:Constants.num_total_questions_ein // 2] else: question_data = self.participant.vars['questions_ein'][ Constants.num_total_questions_ein // 2:Constants.num_total_questions_ein] return { 'question_data': question_data, 'treatment_number': self.player.treatment_number, } def before_next_page(self): self.participant.vars['num_uebersicht'] += 1 class einfragen(Page): form_model = 'player' def get_form_fields(self): return ('ein{}frageS1'.format(self.player.participant.vars['situation_id_ein']), 'ein{}frageS2'.format(self.player.participant.vars['situation_id_ein'])) def is_displayed(self): return self.player.display_if_treatment_2_or_3() def vars_for_template(self): question_data = self.participant.vars['questions_ein'][self.player.participant.vars['num_question_ein'] - 1] return { 'slider_1': "#id_ein{}frageS1".format(question_data['situation_id']), 'slider_2': "#id_ein{}frageS2".format(question_data['situation_id']), 'treatment_nummer': self.player.treatment_number, 'frage_nummer': self.participant.vars['num_question_ein'], 'question_data': question_data, } class einsicher(Page): form_model = 'player' def get_form_fields(self): return ('ein{}sicherS1'.format(self.player.participant.vars['situation_id_ein']), 'ein{}sicherS2'.format(self.player.participant.vars['situation_id_ein'])) def is_displayed(self): return self.player.display_if_treatment_2_or_3() def vars_for_template(self): return { 'treatment_nummer': self.player.treatment_number, 'frage_nummer': self.participant.vars['num_question_ein'], 'question_data': self.participant.vars['questions_ein'][ self.player.participant.vars['num_question_ein'] - 1], } def before_next_page(self): self.player.reihenfolge_ein += 'ein{} '.format(self.player.participant.vars['situation_id_ein']) if self.player.participant.vars['num_question_ein'] != Constants.num_total_questions_ein: self.player.participant.vars['num_question_ein'] += 1 self.player.question_data_ein = self.player.current_question_ein() self.player.participant.vars['situation_id_ein'] = self.player.question_data_ein['situation_id'] class einfrei(Page): form_model = 'player' form_fields = ['einfrei'] def is_displayed(self): return self.player.display_if_treatment_2_or_3() class bedarffrage(Page): form_model = 'player' form_fields = ['bedarffrage'] class assoziationen(Page): form_model = 'player' form_fields = ['assoquadrat', 'assopersonen'] class soziodemoein(Page): def is_displayed(self): return True class soziodemo(Page): form_model = 'player' form_fields = ['geschlecht', 'geschlechtother', 'alter', 'muttersprache', 'mutterspracheother', 'abschluss', 'studienfach', 'beschaeftigung'] class wohnsituation(Page): form_model = 'player' form_fields = ['wohnsituation', 'hausflaeche', 'hausgroesse'] class verantwortung(Page): form_model = 'player' def get_form_fields(self): return ('soziodemozustaendVerant{}'.format(self.player.participant.vars['verant'][0]), 'soziodemozustaendVerant{}'.format(self.player.participant.vars['verant'][1]), 'soziodemozustaendVerant{}'.format(self.player.participant.vars['verant'][2]), 'soziodemozustaendVerant{}'.format(self.player.participant.vars['verant'][3]), 'soziodemozustaendVerant{}'.format(self.player.participant.vars['verant'][4]),) def vars_for_template(self): questions = self.player.participant.vars['verant'] return { 'questions': questions, } class linksrechtsselbst(Page): form_model = 'player' form_fields = ['linksrechtsselbst'] class linksrechtspartei(Page): form_model = 'player' def get_form_fields(self): return ('linksrechtspartei{}'.format(self.player.participant.vars['partei'][0]), 'linksrechtspartei{}'.format(self.player.participant.vars['partei'][1]), 'linksrechtspartei{}'.format(self.player.participant.vars['partei'][2]), 'linksrechtspartei{}'.format(self.player.participant.vars['partei'][3]), 'linksrechtspartei{}'.format(self.player.participant.vars['partei'][4]), 'linksrechtspartei{}'.format(self.player.participant.vars['partei'][5]), 'linksrechtspartei{}'.format(self.player.participant.vars['partei'][6]), 'linksrechtspartei{}'.format(self.player.participant.vars['partei'][7]), 'linksrechtspartei{}'.format(self.player.participant.vars['partei'][8]),) def vars_for_template(self): questions = self.player.participant.vars['partei'] return { 'questions': questions, } class risiko(Page): form_model = 'player' form_fields = ['risiko'] def vars_for_template(self): return { 'questions': [0, ], } def before_next_page(self): self.player.time_ended = datetime.utcnow() class Results(Page): def vars_for_template(self): return { 'treatment_nummer': self.player.treatment_number, 'auszahlung': self.session.config['participation_fee'] } page_sequence.extend([monoeinleitung, monostich, monofragen, monosicherheit, monofrei, seneinleitung, senstich]) for sen_iterator in Constants.total_questions_sen: page_sequence.extend([sen, senvalue, sensicher]) page_sequence.extend([senfrei, ueberuntereinleitung, ueberunterstich, ueberunteruebersicht]) for ueberunter_iterator in Constants.total_questions_ueberunter: page_sequence.extend([ueberunterfragen, ueberuntersicher]) page_sequence.extend( [ueberunterfrei, skatranseinleitung1, skatransstich1, skatransfragen1, skatranseinleitung2, skatransstich2, skatransfragen2, skatransfrei, verteileinleitung, verteilstich]) for verteil_iterator in Constants.total_questions_verteil: page_sequence.extend([verteil]) page_sequence.extend([verteilfrei]) for ausfragen_iterator in Constants.total_questions_aus: page_sequence.extend([ausfragen]) page_sequence.extend([ausfrei, eineinleitung, einstich, einuebersicht, einuebersicht]) for einfragen_iterator in Constants.total_questions_ein: page_sequence.extend([einfragen, einsicher]) page_sequence.extend( [einfrei, bedarffrage, assoziationen, soziodemoein, soziodemo, wohnsituation, verantwortung, linksrechtsselbst, linksrechtspartei, risiko, Results])