from os import environ from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, ) class Constants(BaseConstants): name_in_url = 'questionnaire' players_per_group = None num_rounds = 1 timeout = 300 comment_min_chars = 15 comment_max_chars = 3000 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): liked_theme = models.LongStringField( max_length=Constants.comment_max_chars, blank=False, label='What led your choice of playing one theme or the other?' ) comments = models.LongStringField( max_length=Constants.comment_max_chars, blank=False, label="What information do you remember receiving about other players?" ) def comments_error_message(self, value): return self.long_string_input_error_message(value) def liked_theme_error_message(self, value): return self.long_string_input_error_message(value) def long_string_input_error_message(self, value): if len(value) < Constants.comment_min_chars: return 'Your answer should be at least ' + str(Constants.comment_min_chars) + ' characters long' if len(value) > Constants.comment_max_chars: return 'Your answer should be at most ' + str(Constants.comment_max_chars) + ' characters long'