from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class Instruction(Page): def is_displayed(self): return self.round_number==1 class Experiment(Page): form_model = 'player' form_fields = ['allocation1', 'allocation2'] def before_next_page(self): p = self.player p.shortage1 = p.allocation1 - p.order1 p.shortage2 = p.allocation2 - p.order2 def vars_for_template(self): y1 = self.round_number - 1 return { 'x1': y1, 'player_in_previous_rounds': self.player.in_previous_rounds(), } def error_message(self, values): print('', values) if values["allocation1"] + values["allocation2"] > 100: return 'The sum of the allocation exceeds the capacity' elif values["allocation1"] > Constants.determined_order1[self.round_number-1]: return 'The allocation exceeds the retailer1\'s order' elif values["allocation2"] > Constants.determined_order2[self.round_number-1]: return 'The allocation exceeds the retailer2\'s order' class Results(Page): pass page_sequence = [ Instruction, Experiment, Results ]