

def _get_field(self, question):
    '\n        Create a form field based on a question.\n        '
    if (question.type == 'M'):
        choices = ([('', '')] + [(c, c) for c in question.get_possible_answers()])
        return forms.ChoiceField(label=question.text, required=question.required, widget=forms.Select(attrs={
            'class': 'select_choice_field',
        }), choices=choices)
    if (question.type == 'R'):
        choices = [(c, c) for c in question.get_possible_answers()]
        return forms.ChoiceField(label=question.text, required=question.required, widget=forms.RadioSelect(attrs={
            'class': 'radio_choice_field',
        }), choices=choices)
    if (question.type == 'C'):
        choices = [(c, c) for c in question.get_possible_answers()]
        return forms.MultipleChoiceField(label=question.text, required=question.required, widget=forms.CheckboxSelectMultiple(attrs={
            'class': 'checkbox_choice_field',
        }), choices=choices)
    elif (question.type == 'S'):
        return forms.CharField(label=question.text, required=question.required, widget=forms.TextInput(attrs={
            'class': 'short_text_field',
        }))
    elif (question.type == 'L'):
        return forms.CharField(label=question.text, required=question.required, widget=forms.Textarea(attrs={
            'class': 'long_text_field',
        }))

dataset/ETHPy150Open sunlightlabs/django-simplesurvey/simplesurvey/forms.py SurveyForm._get_field/original