from otree.api import Page def withdraw_from_experiment(player, data): """Record an explicit withdrawal and release the participant's matrix schedule.""" if not isinstance(data, dict) or data.get('type') != 'withdraw': return participant = player.participant if participant.vars.get('finished', False): return { player.id_in_group: dict(type='already_finished'), } if not participant.vars.get('withdrew', False): participant.withdrew = True from matrix_game import release_schedule release_schedule(participant, player.session) return { player.id_in_group: dict(type='withdrawn'), } class ExperimentPage(Page): """Base page that lets a participant explicitly exit the experiment.""" @staticmethod def js_vars(player): return dict( participant_withdrew=player.participant.vars.get('withdrew', False), participant_finished=player.participant.vars.get('finished', False), ) @staticmethod def live_method(player, data): return withdraw_from_experiment(player, data)