from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Introduction(Page): form_model = 'player' class Send(Page): form_model = 'group' form_fields = ['sent_amount'] def is_displayed(self): return self.player.id_in_group == 2 class SendBackWaitPage(WaitPage): pass class SendBack(Page): form_model = 'group' form_fields = ['sent_back_amount'] def is_displayed(self): return self.player.id_in_group == 1 def vars_for_template(self): tripled_amount = self.group.sent_amount * Constants.multiplier return dict( tripled_amount=tripled_amount, prompt='Please an amount from 0 to {}'.format(tripled_amount), ) class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' class Results(Page): form_model = 'player' def vars_for_template(self): return dict( tripled_amount = self.group.sent_amount * Constants.multiplier, last_payoff = self.participant.vars['round1'], ) def before_next_page(self): participant = self.participant player = self.player participant.vars['round2'] = player.payoff class Last_Wait(WaitPage): pass class Both_Game_Results(Page): form_model = 'player' def vars_for_template(self): return dict( tripled_amount = self.group.sent_amount * Constants.multiplier, round1_payoff = self.participant.vars['round1'], round2_payoff = self.participant.vars['round2'], yourID = self.participant.code, endgamenumber = 1, ) page_sequence = [Introduction, Send, SendBackWaitPage, SendBack, ResultsWaitPage, Results, Last_Wait, Both_Game_Results]