

def __init__(self, question_set, *args, **kwargs):
    '\n        Create a form object from a question set.\n        Method takes and option related_object keyword argument that relates\n        the survey to an instance of a Django model.\n        '
    related_object = kwargs.get('related_object', None)
    try:
        del kwargs['related_object']
    except KeyError:
        pass
    answer_set = kwargs.get('answer_set', None)
    try:
        del kwargs['answer_set']
    except KeyError:
        pass
    super(self.__class__, self).__init__(*args, **kwargs)
    for question in question_set.questions.order_by('order'):
        name = ('answer_for_%i' % question.id)
        field = self._get_field(question)
        if field:
            self.fields[name] = field
    if related_object:
        ct = ContentType.objects.get_for_model(related_object)
        related = ('%i:%s' % (ct.id, related_object.pk))
        self.fields['related'] = forms.CharField(widget=forms.HiddenInput, initial=related)
        if answer_set:
            self.data['related'] = related
    if answer_set:
        self.fields['answer_set'] = forms.CharField(widget=forms.HiddenInput, initial=answer_set.pk)
        self.data['answer_set'] = answer_set.pk
        self.is_bound = True
        for (question, answer) in answer_set.q_and_a():
            name = ('answer_for_%i' % question.id)
            self.data[name] = answer.text
    self.fields['question_set'] = forms.CharField(widget=forms.HiddenInput, initial=question_set.slug)
    if answer_set:
        self.data['question_set'] = question_set.slug

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