from ._builtin import Page from .models import Constants import math class Consent(Page): timeout_seconds = Constants.consent_timeout form_model = 'player' form_fields = ['consent'] timeout_submission = {'consent': False} def vars_for_template(self): if self.session.config.get('name') == 'survey': self.template_name = 'consent/AltConsent.html' return {'consent_timeout_min': math.ceil(self.timeout_seconds / 60)} def is_displayed(self): return self.round_number == 1 def before_next_page(self): if self.timeout_happened: self.player.consent = False self.player.is_dropout = True self.player.participant.vars['dropout'] = True self.player.participant.vars['consent_dropout'] = True else: self.player.is_dropout = not self.player.consent self.player.participant.vars['dropout'] = self.player.is_dropout self.player.participant.vars['consent_dropout'] = self.player.is_dropout class BlockDropouts(Page): def is_displayed(self): return self.round_number == 1 and self.player.participant.vars.get('consent_dropout', False) def vars_for_template(self): return { 'redirect_url': self.session.config['consent_dropout'] } page_sequence = [ Consent, BlockDropouts, ]