from otree.api import * # simpler imports: Page, cu, etc. from .models import Constants as C # so C.PAYOFF_BY_INFOSET works class BonusPage(Page): def _get_tg_int(self): tg = self.participant.vars.get('tg') or getattr(self.player, 'tg', None) try: return int(tg) if tg is not None else None except (TypeError, ValueError): return None def vars_for_template(self): tg = self.participant.vars.get('tg') or getattr(self.player, 'tg', None) info_set = self.participant.vars.get('info_set') or getattr(self.player, 'info_set', None) if info_set is None: raise RuntimeError("info_set not assigned. Set it in the first app.") amount = C.PAYOFF_BY_INFOSET[info_set] # cu(...) current_total = self.participant.payoff # BEFORE adding bonus total_after = current_total + amount # what user will have AFTER this page return dict( tg=tg, info_set=info_set, amount=amount, current_total=current_total, total_after=total_after, ) def before_next_page(self): info_set = self.participant.vars.get('info_set') or getattr(self.player, 'info_set', None) amount = C.PAYOFF_BY_INFOSET[int(info_set)] self.player.payoff += amount # <-- add only the bonus page_sequence = [BonusPage]