from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Intro(Page): def is_displayed(self): return self.round_number == 1 class Contribute(Page): form_model = 'player' form_fields = ['contribution'] class FirstWaitPage(WaitPage): pass class Punish(Page): form_model = 'player' form_fields = ['punish1', 'punish2'] def is_displayed(self): return self.group.punishment def vars_for_template(self): others = self.player.get_others_in_group() #returns a list of the other two group members, ordered by ID in group return dict( contr1=others[0].contribution, contr2=others[1].contribution, ) class ResultsWaitPage(WaitPage): after_all_players_arrive = 'set_payoffs' class Results(Page): pass class End(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def vars_for_template(self): all_payoffs = [p.payoff for p in self.player.in_all_rounds()] total_payoff = sum(all_payoffs) return dict( total=total_payoff, ) page_sequence = [Intro, Contribute, FirstWaitPage, Punish, ResultsWaitPage, Results, End]