from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Send(Page): form_model = 'group' form_fields = ['owner_contract'] def vars_for_template(self): return dict(player_in_previous_rounds=self.player.in_previous_rounds()) def is_displayed(self): return self.player.id_in_group==1 class Penalty(Page): form_model='group' form_fields = ['owner_penalty'] def is_displayed(self): return self.player.id_in_group==1 and self.group.owner_contract== True class Discount(Page): form_model = 'group' form_fields = ['owner_discount'] def is_displayed(self): return self.player.id_in_group == 1 and self.group.owner_contract == False def before_next_page(self): self.group.Numbers() class SendBack(Page): form_model = 'group' form_fields = ['renter_action'] def vars_for_template(self): return dict(player_in_previous_rounds=self.player.in_previous_rounds()) def is_displayed(self): return self.player.id_in_group == 2 and self.group.owner_contract == True class SendBack2(Page): form_model = 'group' form_fields = ['renter_action'] def vars_for_template(self): return dict(player_in_previous_rounds=self.player.in_previous_rounds()) def is_displayed(self): return self.player.id_in_group == 2 and self.group.owner_contract == False def before_next_page(self): self.group.Numbers2() class WaitforP1(WaitPage): body_text = "Waiting for the Owner to make his choice" class WaitforP2(WaitPage): body_text = "Waiting for the Renter to make his choice" class ResultsWaitPag(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() def is_displayed(self): return self.group.owner_contract == True and self.group.owner_penalty == True class ResultsWaitPag2(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() def is_displayed(self): return self.group.owner_contract == False class ResultsWaitPag3(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() def is_displayed(self): return self.group.owner_contract == True and self.group.owner_penalty == False class Results_final(Page): form_model = 'group' def is_displayed(self): return self.group.owner_contract == True class Results_final1(Page): form_model = 'group' def is_displayed(self): return self.group.owner_contract == False class ResultsSummary(Page): def is_displayed(self): return self.round_number == Constants.num_rounds def after_all_players_arrive(self): self.group.set_payoffs() def vars_for_template(self): return dict(total_points1=self.participant.payoff_plus_participation_fee(), payoff_points1=self.participant.payoff.to_real_world_currency(self.session), payoff_points2=self.participant.payoff.to_real_world_currency(self.session), total_points2=self.participant.payoff_plus_participation_fee(), player_in_all_rounds=self.player.in_all_rounds()) class Chat1(Page): def vars_for_template(self): return dict( nickname="Participant " + str(self.participant.id_in_session)+str(self.round_number) ) timer_text = 'Time left to discuss:' timeout_seconds = 90 class BeforeResultsWP(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() def before_next_page(self): self.group.prev_players() def is_displayed(self): return self.group.owner_contract == True and self.group.owner_penalty == True class BeforeResultsWP2(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() def is_displayed(self): return self.group.owner_contract == False def before_next_page(self): self.group.prev_players() class BeforeResultsWP3(WaitPage): def after_all_players_arrive(self): self.group.set_payoffs() def before_next_page(self): self.group.prev_players() def is_displayed(self): return self.group.owner_contract == True and self.group.owner_penalty == False page_sequence = [Chat1, Send, Penalty, Discount, WaitforP1, SendBack, SendBack2, WaitforP2, ResultsWaitPag, ResultsWaitPag2, ResultsWaitPag3, Results_final, Results_final1, BeforeResultsWP, BeforeResultsWP2, BeforeResultsWP3, ResultsSummary]