from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from django.conf import settings class P0(Page): form_model = 'player' form_fields = ['participation_number'] def error_message(self, value): if value['participation_number'] not in self.session.vars['participation_numbers']: return '''This is not a valid participation number!''' class P1(Page): pass class P2a(Page): form_model = 'player' form_fields = ['control_slider'] def vars_for_template(self): return { 'sliders_low': int(Constants.percent_sliders_to_be_moved_low/100*Constants.num_sliders), 'sliders_high': int(Constants.percent_sliders_to_be_moved_high/100*Constants.num_sliders) } def error_message(self, value): if value['control_slider'] != 50: return '''Please set the slider to 50 and click "Next"!''' class P2b(Page): form_model = 'player' def get_form_fields(self): if self.player.slider_treatment == 'high': return Constants.slider_list_high_effort_treatment else: return Constants.slider_list_low_effort_treatment def vars_for_template(self): return { 'sliders_low': int(Constants.percent_sliders_to_be_moved_low/100*Constants.num_sliders), 'sliders_high': int(Constants.percent_sliders_to_be_moved_high/100*Constants.num_sliders) } def error_message(self, value): for field in P2b.get_form_fields(self): print(field) if value[field] != 50: return 'Not all sliders are set to 50 yet!' class P3(Page): form_model = 'player' form_fields = ['donation'] def vars_for_template(self): return { 'sliders_low': int(Constants.percent_sliders_to_be_moved_low/100*Constants.num_sliders), 'sliders_high': int(Constants.percent_sliders_to_be_moved_high/100*Constants.num_sliders), 'partner_treatment': self.player.partner_treatment() } def before_next_page(self): if self.player.role() == 'decider': self.group.set_implemented_donation() self.group.set_payoffs_dictator_game() class P4(Page): form_model = 'player' form_fields = ['ownership'] # See Reb, Connelly - 2007 class P5(Page): form_model = 'player' form_fields = ['belief'] def vars_for_template(self): return { 'bonus': Constants.belief_bonus['win'], 'sliders_low': int(Constants.percent_sliders_to_be_moved_low / 100 * Constants.num_sliders), 'sliders_high': int(Constants.percent_sliders_to_be_moved_high / 100 * Constants.num_sliders), 'remaining_endowment': Constants.endowment - self.player.donation } # def belief_low_max(self): # return Constants.endowment - self.player.donation # def belief_high_max(self): # return Constants.endowment - self.player.donation # def error_message(self, values): # if values["belief_low"] + values["belief_high"] != Constants.endowment - self.player.donation: # return 'The entered numbers must add up to your remaining endowment of %s.' % (Constants.endowment - self.player.donation) def before_next_page(self): self.player.set_payoffs_beliefs() if self.player.role() == 'decider': self.group.set_payoff_decider() if self.player.role() == 'receiver': self.group.set_payoff_receiver() class P6(Page): form_model = 'player' form_fields = ['risk'] # Bonin, Dohmen, Falk, Huffman, Sunde - Cross-sectional earnings risk and occupational sorting: The role of risk attitudes - 2007 class P7(Page): form_model = 'player' form_fields = ['age', 'gender', 'country', 'education'] class P8(Page): def vars_for_template(self): return {'player_role': self.player.role(), 'group_implemented_donation': self.group.implemented_donation, 'player_payoff_dictator_game': self.player.payoff_dictator_game, 'participation_fee_in_points': Constants.participation_fee_in_points, 'belief_bonus': Constants.belief_bonus['win'], 'player_payoff_belief': self.player.payoff_belief, 'player_payoff': Constants.participation_fee_in_points + self.player.payoff, 'your_participation_number': self.player.participation_number } page_sequence = [ P0, P1, P2a, P2b, P3, P4, P5, P6, P7, P8 ]