from otree.api import Currency as c, currency_range from ._builtin import Page, WaitPage from .models import Constants class TaskTDecision(Page): template_name = 'games_solo/TimeDecision.html' form_model = 'player' form_fields = ['time_decision'] def vars_for_template(self): touch = False if self.participant.vars.get('is_mobile') or self.participant.vars.get('is_tablet'): touch = True return {'touch': touch} def before_next_page(self): self.player.set_time_payoff() class TaskRInstructions(Page): template_name = 'games_solo/BretInstructions.html' # variables for use in template def vars_for_template(self): return { 'num_rows': Constants.num_rows, 'num_cols': Constants.num_cols, 'num_boxes': Constants.num_rows * Constants.num_cols, 'num_nobomb': Constants.num_rows * Constants.num_cols - 1, 'box_value': Constants.box_value, 'time_interval': Constants.time_interval, } class TaskRDecision(Page): template_name = 'games_solo/BretDecision.html' # form fields on player level form_model = 'player' form_fields = [ 'bomb', 'boxes_collected', 'bomb_row', 'bomb_col', ] # BRET settings for Javascript application def vars_for_template(self): reset = self.participant.vars.get('reset',False) if reset: del self.participant.vars['reset'] input = not Constants.devils_game if not Constants.dynamic else False otree_vars = { 'reset': reset, 'input': input, 'random': Constants.random, 'dynamic': Constants.dynamic, 'num_rows': Constants.num_rows, 'num_cols': Constants.num_cols, 'feedback': Constants.feedback, 'undoable': Constants.undoable, 'box_width': Constants.box_width, 'box_height': Constants.box_height, 'time_interval': Constants.time_interval, } return { 'otree_vars': otree_vars } def before_next_page(self): self.participant.vars['reset'] = True self.player.set_bret_payoff() class TaskRResults(Page): template_name = 'games_solo/BretResults.html' # variables for use in template def vars_for_template(self): total_payoff = sum([p.bret_payoff for p in self.player.in_all_rounds()]) self.participant.vars['bret_payoff'] = total_payoff return { 'player_in_all_rounds': self.player.in_all_rounds(), 'box_value': Constants.box_value, 'boxes_total': Constants.num_rows * Constants.num_cols, 'boxes_collected': self.player.boxes_collected, 'bomb': self.player.bomb, 'bomb_row': self.player.bomb_row, 'bomb_col': self.player.bomb_col, 'round_result': self.player.round_result, 'round_to_pay': self.participant.vars['round_to_pay'], 'payoff': self.player.bret_payoff, 'total_payoff': total_payoff, } class TaskDDecision(Page): template_name = 'games_solo/DictatorDecision.html' form_model = 'player' form_fields = ['dictator_decision'] def vars_for_template(self): partner_treatment = self.player.dictator_partner if partner_treatment == 'name': partner = f"The second participant is called {self.player.dictator_partner_name}." elif partner_treatment == 'same_class': partner = "The second participant is also in your class." elif partner_treatment == 'other_house': partner = "The second participant is from another house." elif partner_treatment == 'other_region': partner = "The second participant comes from another house/section in the Civil Service Academy." else: partner = '' if self.participant.vars.get('is_teacher'): partner = '' touch = False if self.participant.vars.get('is_mobile') or self.participant.vars.get('is_tablet'): touch = True return { 'partner': partner, 'touch': touch } def before_next_page(self): self.player.set_dictator_payoff() class TaskMDecision(Page): template_name = 'games_solo/MoralDecision.html' form_model = 'player' form_fields = [f'moral_decision_{n}' for n in range(1, Constants.moral_num_choices + 1)] def vars_for_template(self): return {'is_creteil': self.participant.vars.get('is_creteil')} def before_next_page(self): self.player.set_moral_payoff() class TaskMResults(Page): template_name = 'games_solo/MoralFeedback.html' def vars_for_template(self): choice_to_pay = self.participant.vars['moral_choice_to_pay'] if choice_to_pay == 0: feedback = f'keep {self.player.moral_payoff} credits for you and not to donate to UNICEF.' elif choice_to_pay == 1: feedback = f'to donate {Constants.moral_endowment} credits to UNICEF and not to keep anything for yourself' return {'feedback': feedback} class TaskLDecision(Page): template_name = 'games_solo/LyingDecision.html' form_model = 'player' form_fields = ['lying_decision'] def vars_for_template(self): is_IE = False if self.request.user_agent.browser.family == 'IE': is_IE = True return {'is_IE': is_IE} def before_next_page(self): self.player.lying_payoff = Constants.lying_outcomes[self.player.lying_decision - 1] tasks_with_payoff = ['time', 'bret', 'dictator', 'moral', 'lying'] self.player.payoff = sum( p for p in [getattr(self.player, t + '_payoff') for t in tasks_with_payoff] if p is not None) page_sequence = [ TaskTDecision, TaskRInstructions, TaskRDecision, TaskRResults, TaskDDecision, TaskMDecision, TaskMResults, TaskLDecision, ]