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.StringField( choices=['Animal', 'Food', 'Summer'], widget=widgets.RadioSelectHorizontal, label='Which theme did you like best?' ) comments = models.LongStringField( max_length=3000, blank=False, label="What are your comments on the experiment? (what you liked about it, what you didn't like; your answer should be at least " + str(Constants.comment_min_chars) + " characters long.)" ) def comments_error_message(player, value): print('value lenth is', len(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'