from ._builtin import Page, WaitPage from otree.api import Currency as c, currency_range from .models import Constants class Introduction(Page): """Description of the game: How to play and returns expected""" pass class Article(Page): pass class Donation_decision(Page): """Player: Choose how much to contribute""" form_model = 'player' form_fields = ['donate'] class Notcontribute(Page): def is_displayed(self): return self.player.donate == "寄付しない" def before_next_page(self): self.player.contribution = 0 class Contribute(Page): """Player: Choose how much to contribute""" def is_displayed(self): return self.player.donate == "寄付する" form_model = 'player' form_fields = ['contribution'] class ResultsWaitPage(WaitPage): body_text = "他のプレーヤーが寄付金額を入力するまで待ってください." class Results(Page): """Players payoff: How much each has earned""" def vars_for_template(self): return dict( total_earnings = Constants.endowment-self.player.contribution, future = (1 + (int(self.player.matching_rate)* 0.01)) *self.player.contribution ) page_sequence = [Introduction, Article, Donation_decision, Notcontribute, Contribute, ResultsWaitPage, Results]