from . import models from ._builtin import Page, WaitPage import datetime class Splash(Page): pass class Intro(Page): form_model = 'player' def is_displayed(self): return ( self.round_number == 2 ) def before_next_page(self): self.player.participant.vars['f_news'] = self.player.f_news def vars_for_template(self): return { 'f_news': self.player.f_news} class welcome(Intro): def is_displayed(self): return ( self.round_number == 2 ) class Introduction(Intro): def is_displayed(self): return ( self.round_number == 2 ) class InformationSheet(Intro): def is_displayed(self): return ( self.round_number == 1 ) class Consent(Page): form_fields = ['consent1', 'consent2', 'consent3', 'consent4', 'consent5', 'Date'] form_model = 'player' def is_displayed(self): return ( self.round_number == 1 ) def error_message(self, values): current_date = datetime.date.today() date_formats = ["%d/%m/%Y", "%d-%m-%Y"] solutions = {} for date_format in date_formats: formatted_date = current_date.strftime(date_format) solutions['Date'] = formatted_date error_messages = {} for field_name in solutions: if values[field_name] != current_date.strftime(date_formats[0]) and values[ field_name] != current_date.strftime(date_formats[1]): error_messages[field_name] = "Please enter today's date in DD-MM-YYYY or DD/MM/YYY format" # Error occurred for all format options, return the error messages return error_messages def before_next_page(self): self.player.participant.vars['f_news'] = self.player.f_news self.player.participant.vars['consent5'] = int(self.player.consent5), def app_after_this_page(self, upcoming_apps): if self.player.consent5 == 1: return upcoming_apps[-1] class attention_check1(Page): template_name = "Welcome/attention_check.html" form_model = 'player' form_fields = ["Attention_Check1"] def is_displayed(self): return ( self.round_number == 1 ) class attention_check2(Page): template_name = "Welcome/attention_check.html" form_model = 'player' form_fields = ["Attention_Check2"] def is_displayed(self): return ( self.round_number == 2 ) page_sequence = [ # Splash, InformationSheet, Consent, attention_check1, attention_check2, welcome, # Introduction, ]