from . import models from ._builtin import Page, WaitPage from .models import Constants from otree.common import safe_json class Introduction(Page): def is_displayed(self): return self.round_number == 1 class Offer(Page): def is_displayed(self): return self.player.role() == 'principal' form_model = models.Group form_fields = ['principal_wage_offer'] #class OfferWaitPage(WaitPage): # def vars_for_template(self): # if self.player.role() == 'agent': # body_text = "You are Participant 2. Waiting for Participant 1 to propose a wage offer." # else: # body_text = "Waiting for Participant 2." # return {'body_text': body_text} #class Accept(Page): # def is_displayed(self): # return self.player.role() == 'agent' # # form_model = models.Group # form_fields = ['contract_accepted'] # # timeout_submission = { # 'contract_accepted': False, # 'agent_work_effort': 0, # } class WorkEffort(Page): def is_displayed(self): #if self.group.contract_accepted == True: return self.player.role() == 'agent' form_model = models.Group form_fields = ['agent_effort_{}'.format(int(i)) for i in range(0,9+1)] # timeout_submission = { # 'contract_accepted': False, # 'agent_work_effort': 0, # } class ResultsWaitPage(WaitPage): def body_text(self): if self.player.role() == 'principal': return "Waiting for the agent to respond." else: return "Waiting for the principal to make an offer." def after_all_players_arrive(self): self.group.set_payoffs() class Results(Page): def vars_for_template(self): return { 'total_payoff': sum( [p.payoff for p in self.player.in_all_rounds()]), 'player_in_all_rounds': self.player.in_all_rounds() } page_sequence = [Introduction, Offer, WorkEffort, ResultsWaitPage, Results]