from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants from captcha.fields import ReCaptchaField class Instructions_3(Page): def vars_for_template(self): return {'bonus': Constants.bonus, 'n_sections': Constants.n_sections} class WeightChange(Page): form_model = 'player' form_fields = ['ideal_weight', 'change_weight', 'what_change', 'why_change', 'lose', 'gain', 'not_lose', 'not_gain', 'other_lose', 'other_gain', 'other_not_lose', 'other_not_gain', 'attention_check_weight'] class Instructions_4(Page): def vars_for_template(self): return {'bonus': Constants.bonus, 'n_sections': Constants.n_sections} class Scenarios1(Page): def is_displayed(self): return self.player.option == 1 form_model = 'player' form_fields = ['g1A', 'g1B', 'g1C', 'g2A', 'g2B', 'g2C'] class Scenarios2(Page): def is_displayed(self): return self.player.option == 2 form_model = 'player' form_fields = ['g1A', 'g1B', 'g1C', 'g2A', 'g2B', 'g2C'] class Costs(Page): form_model = 'player' form_fields = ['costs1', 'costs2', 'costs3', 'costs4', 'costs5', 'costs_d_1', 'costs_d_2', 'costs_d_3', 'costs_d_4', 'costs_d_5', 'avg_life_exp1', 'avg_life_exp2', 'avg_life_exp3', 'avg_life_exp4', 'attention_check_three', 'health_bmiscale'] def vars_for_template(self): return {'img_to_show': Constants.sil_pic} class Instructions_5(Page): def vars_for_template(self): return {'bonus': Constants.bonus, 'n_sections': Constants.n_sections} class IncomeBeliefs(Page): form_model = 'player' form_fields = ['avg_income_s2', 'avg_income_s8', 'norm_q1', 'norm_q2', 'norm_q3', 'norm_q4','norm_q5', 'norm_q6', 'obese_q1', 'obese_q2', 'obese_q3', 'obese_q4', 'obese_q5', 'obese_q6'] def vars_for_template(self): return {'img_to_show': Constants.sil_pic} def error_message(self, values): print('values is', values) if values['norm_q1'] + values['norm_q2'] + values['norm_q3']\ + values['norm_q4'] + values['norm_q5'] + values['norm_q6'] != 100: return 'The numbers in the first block must add up to 100' print('values is', values) if values['obese_q1'] + values['obese_q2'] + values['obese_q3']\ + values['obese_q4'] + values['obese_q5'] + values['obese_q6'] != 100: return 'The numbers in the second block must add up to 100' class Instructions_6(Page): def vars_for_template(self): return {'bonus': Constants.bonus, 'n_sections': Constants.n_sections} class Nutrition1(Page): form_model = 'player' form_fields = ['juiceserv_f1', 'sweetjuice_f1', 'regsoftdrink_f1', 'dietsoftdrink_f1', 'prepackaged_f1', 'caffeine_f1', 'alcohol_f1', 'eatsweets_f2_a', 'eatmore_f2_b', 'drinkmore_fe_c', 'juiceserv_f3', 'sweetjuice_f3', 'regsoftdrink_f3', 'dietsoftdrink_f3', 'prepackaged_f3', 'caffeine_f3', 'alcohol_f3', 'healthimportance_f4'] class Nutrition2(Page): form_model = 'player' form_fields = ['fruit_f5_a', 'foodwithsurgar_f5_b', 'vegetables_f5_c', 'fattyfood_f5_d', 'saltyfood_f5_g', 'water_f5_h', 'unsuturatedfat_f6_a', 'transfat_f6_b', 'saturatedfats_f6_c'] class Nutrition3(Page): form_model = 'player' form_fields = ['dietcola_f7_a', 'plainyoghurt_f7_b', 'icecream_f7_c', 'tomatoketchup_f7_d', 'watermelon_f7_e', 'breakfast_f8_a', 'frozenbreakfst_f8_b', 'bread_f8_c', 'bakedbeans_f8_d', 'redmeat_f8_e', 'oats_f9_a', 'banana_f9_b', 'whiterice_f9_c', 'eggs_f9_d', 'potatoeswithskin_f9_e', 'pasta_f9_e', 'poultry_f10_a', 'cheese_f10_b', 'fruit_f10_c', 'bakedbeans_f10_d', 'butter_f10_e', 'nuts_f10_e', 'cheese_f11_a', 'rice_f11_b', 'irish_f11_c', 'plantains_f11_e', 'calciumamount_f12', 'mostcalories_f13', 'yoghurt_f14', 'flavor_f15', 'restaurant_f17', 'attention_check_salt'] class Nutrition4(Page): form_model = 'player' form_fields = ['sugardisease_f16', 'heartdisprevention_f18', 'expertdiabetes_f19', 'raisecholestol_f20', 'highglycemic_f21', 'fiberdecrease_f22', 'obese', 'normalweight', 'primary_shopper', 'health'] def before_next_page(self): self.player.set_payoffs() class Results(Page): form_model = 'player' def vars_for_template(self): this_section_payoff = self.player.payoff tot_payoff = self.participant.payoff return { 'participation_fee': Constants.participation_fee, 'this_section_payoff': this_section_payoff, 'tot_payoff': tot_payoff} class End(Page): form_model = 'player' def vars_for_template(self): qualified = self.participant.vars.get('qualified') return {'qualified': qualified} page_sequence = [ Instructions_3, WeightChange, Instructions_4, Scenarios1, Scenarios2, Costs, Instructions_5, IncomeBeliefs, Instructions_6, Nutrition1, Nutrition2, Nutrition3, Nutrition4, Results, End ]