from django.forms.widgets import ChoiceWidget from otree.api import ( models, widgets, BaseConstants, BaseSubsession, BaseGroup, BasePlayer, ) class Likert7Widget(ChoiceWidget): input_type = 'radio' label = '' template_name = 'survey/likert_7.html' option_template_name = 'survey/likert_7_option.html' default_labels = ['Strongly disagree', 'Disagree', 'Somewhat disagree', 'Neutral', 'Somewhat agree', 'Agree', 'Strongly agree'] understand_labels = ['Extremely easy', 'Moderately easy', 'Slightly easy', 'Neither easy nor difficult', 'Slightly difficult', 'Moderately difficult', 'Extremely difficult'] def get_context(self, name, value, attrs): context = super().get_context(name, value, attrs) for item in context['widget']['optgroups']: idx = int(item[1][0]['index']) if name == 'understand': item[1][0]['label'] = self.understand_labels[idx] else: item[1][0]['label'] = self.default_labels[idx] return context def __init__(self, attrs=None): super().__init__(attrs) self.choices = [(idx, '') for idx in range(1, 8)] class Constants(BaseConstants): name_in_url = 'survey' players_per_group = None num_rounds = 1 class Subsession(BaseSubsession): pass class Group(BaseGroup): pass class Player(BasePlayer): probability = models.LongStringField( choices=['DOWN', 'MIDDLE', 'UP'], widget=widgets.RadioSelect, label='', ) pairing = models.IntegerField( widget=Likert7Widget, label='', ) strategy_1 = models.LongStringField(label='') strategy_2 = models.LongStringField(label='') strategy_3 = models.LongStringField(label='') concern_up = models.IntegerField(widget=Likert7Widget, label='') concern_meet = models.IntegerField(widget=Likert7Widget, label='') concern_down = models.IntegerField(widget=Likert7Widget, label='') appropriate_1 = models.IntegerField(widget=Likert7Widget, label='') appropriate_2 = models.IntegerField(widget=Likert7Widget, label='') uncomfortable_1 = models.IntegerField(widget=Likert7Widget, label='') uncomfortable_2 = models.IntegerField(widget=Likert7Widget, label='') honest = models.IntegerField(widget=Likert7Widget, label='') gender = models.LongStringField(choices=['Female', 'Male', 'Other'], label='') age = models.IntegerField(min=13, max=125, label='') understand = models.IntegerField(widget=Likert7Widget, label='') other = models.LongStringField(label='', blank=True)