# Definition of views/pages for the survey. # Please note: When using oTree 2.x, this file should be called "pages.py" instead of "views.py" # from otree.api import Currency as c, currency_range from . import models from ._builtin import Page, WaitPage from .models import Constants from otreeutils.surveys import SurveyPage, setup_survey_pages import time class SurveyIntro(Page): pass # let's create the survey pages here # unfortunately, it's not possible to create them dynamically class SurveyPage1(SurveyPage): # timeout_seconds = 120 debug_fill_forms_randomly = True # enable random data input if APPS_DEBUG is True def is_displayed(self): return (not self.participant.vars.get('finished',0)) class SurveyPage2(SurveyPage): # non-incentivized elicitation of time preferences # timeout_seconds = 120 debug_fill_forms_randomly = True # enable random data input if APPS_DEBUG is True def is_displayed(self): return (not self.participant.vars.get('finished',0)) class SurveyPage3(SurveyPage): # timeout_seconds = 120 debug_fill_forms_randomly = True # enable random data input if APPS_DEBUG is True def is_displayed(self): return (not self.participant.vars.get('finished',0)) class SurveyPage4(SurveyPage): # timeout_seconds = 120 debug_fill_forms_randomly = True # enable random data input if APPS_DEBUG is True def is_displayed(self): return (not self.participant.vars.get('finished',0)) class SurveyPage5(SurveyPage): # timeout_seconds = 120 debug_fill_forms_randomly = True # enable random data input if APPS_DEBUG is True def is_displayed(self): return (not self.participant.vars.get('finished', 0)) def before_next_page(self): # time.time() returns the number of seconds passed since epoch (January 1, 1970, 00:00:00) self.participant.vars['experiment_ending_time'] = time.time() # def get_context_data(self, **kwargs): # # get the context data generated by SurveyPage # ctx_data = super().get_context_data(**kwargs) # # # remove the form we don't want to display for the respective treatment # if self.player.treatment == 1: # remove_form = 2 # else: # remove_form = 1 # # del ctx_data['survey_forms']['treatment_%d_form' % remove_form] # # # return the modified context data # return ctx_data # Create a list of survey pages. # The order is important! The survey questions are taken in the same order # from the SURVEY_DEFINITIONS in models.py survey_pages = [ SurveyPage1, SurveyPage2, SurveyPage3, SurveyPage4, # SurveyPage5, ] # Common setup for all pages (will set the questions per page) setup_survey_pages(models.Player, survey_pages) page_sequence = [ # SurveyIntro, ] # add the survey pages to the page sequence list page_sequence.extend(survey_pages) # page_sequence.append(Consent)