예제 #1
0
파일: tests.py 프로젝트: lugnitdgp/avskr2.0
 def test_field_validate_slug_length(self):
     max_slug_length = 2000
     form = Form.objects.create(title="Test")
     field = Field(form=form,
                   label='x' * (max_slug_length + 1), field_type=NAMES[0][0])
     field.save()
     self.assertLessEqual(len(field.slug), max_slug_length)
예제 #2
0
    def import_questionnaires(self):
        for q in self.data['questionnaires']:
            print '>>  Questionnaire(%s)' % str(q)

            new_questionnaire = Questionnaire(title=q['title'], position=q['position'], intro=q['intro'], response=q['response'])
            new_questionnaire.save()

            for field in q['fields']:
                self.print_indent('>>  QuestionnaireField(%s)' % str(field))

                new_field = Field(form=new_questionnaire, label=field['label'], field_type=self._convert_field_type(field['type']), choices=field['choices'] or '', required=field['required'] is not False, visible=field['visible'] is not False)
                new_field.save()
                self.questionnaire_field_ids[field['id']] = new_field.id

            for submission in q['submissions']:
                new_formentry = FormEntry(form=new_questionnaire)
                new_cfe = ConversationFormEntry(position=q['position'], questionnaire=new_questionnaire)

                for answer in submission:
                    self.print_indent('>>  QuestionnaireAnswer(%s)' % str(answer), 8)

                    new_formentry.entry_time = answer['entry_time']
                    new_formentry.save()

                    new_fieldentry = FieldEntry(field_id=self._get_questionnaire_field_id(answer['field_id']), value=answer['value'], entry=new_formentry)
                    new_fieldentry.save()

                    if answer['conversation_id']:
                        new_cfe.entry = new_formentry
                        new_cfe.conversation = Conversation.objects.get(pk=self._get_chat_id(answer['conversation_id']))
                        new_cfe.created_at = answer['entry_time']
                        new_cfe.save()
예제 #3
0
    def test_field_validate_slug_names(self):
        form = Form.objects.create(title="Test")
        field = Field(form=form,
                label="First name", field_type=NAMES[0][0])
        field.save()
        self.assertEqual(field.slug, 'first_name')

        field_2 = Field(form=form,
                label="First name", field_type=NAMES[0][0])
        self.assertRaises(IntegrityError, field_2.save)
예제 #4
0
    def test_field_validate_slug_names(self):
        form = Form.objects.create(title="Test")
        field = Field(form=form, label="First name", field_type=NAMES[0][0])
        field.save()
        self.assertEqual(field.slug, 'first_name')

        field_2 = Field(form=form, label="First name", field_type=NAMES[0][0])
        try:
            field_2.save()
        except IntegrityError:
            self.fail("Slugs were not auto-unique")
    def test_field_validate_slug_names(self):
        form = Form.objects.create(title="Test")
        field = Field(form=form,
                label="First name", field_type=NAMES[0][0])
        field.save()
        self.assertEqual(field.slug, 'first_name')

        field_2 = Field(form=form,
                label="First name", field_type=NAMES[0][0])
        try:
            field_2.save()
        except IntegrityError:
            self.fail("Slugs were not auto-unique")
예제 #6
0
    def post(self, request):
        print(request.POST)
        form1 = CreateField(request.POST, prefix="1")

        context = {
            "no_of_fields": request.session["no_of_fields"]
        }
        namelist = []
        argsdict = {}
        booltmp = True
        for i in range(0, request.session["no_of_fields"]):
            tmp = "form" + str(i)
            namelist.append(tmp)
            tmpform = CreateField(request.POST, prefix=tmp)
            argsdict[tmp] = tmpform
            if not tmpform.is_valid():
                booltmp = False

        context["namelist"] = namelist
        context["argsdict"] = argsdict
        if booltmp is False:
            return render(request, self.template_name, context)

        for i in range(0, request.session["no_of_fields"]):
            tmp = "form" + str(i)
            tmpform = argsdict[tmp]
            label = tmpform.cleaned_data.get('label')

            field_type = tmpform.cleaned_data.get('field_type')
            required = tmpform.cleaned_data.get('required')
            default = tmpform.cleaned_data.get('default')
            placeholder_text = tmpform.cleaned_data.get('placeholder_text')
            help_text = tmpform.cleaned_data.get('help_text')
            choices = tmpform.cleaned_data.get('choices')

            f = Field()
            f.form = Form.objects.get(id=request.session["formid"])
            f.label = label
            f.field_type = field_type
            f.required = required
            f.default = default
            f.placeholder_text = placeholder_text
            f.help_text = help_text
            f.choices = choices
            f.save()

        return redirect('forms:main')