Esempio n. 1
0
    def test_validate_type_ok(self):
        form = ContactForm({
            'user': self.user.pk,
            'kind': self.label.pk,
            'value': '+01234567890',
        })

        self.assertTrue(form.is_valid())
Esempio n. 2
0
def contactview(request):
    form = ContactForm()
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save(commit = True)
            print('details saved successfully')
            return render(request, 'testapp/thanks.html')

    return render(request, 'testapp/contact.html', {'form':form})
Esempio n. 3
0
    def test_validate_type(self):
        form = ContactForm({
            'user': self.user.pk,
            'kind': self.label.pk,
            'value': 'abc',
        })

        self.assertFalse(form.is_valid())
        self.assertIn('value', form.errors)
        self.assertEqual(form.errors['value'],
                         [six.text_type(form.error_messages['wrong_type'])])
Esempio n. 4
0
def contact_view(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            form.save()
            form = ContactForm()
            return render(request, 'contact.html', {'form': form})
        else:
            return HttpResponse('<h1> Invalid Form</h1>')
    else:
        form = ContactForm()
        return render(request, 'contact.html', {'form': form})
Esempio n. 5
0
    def test_label_required(self):
        label = ContactClassifierLabelFactory(required=True)
        form = ContactForm({
            'user': self.user.pk,
            'kind': label.pk,
            'value': None,
        })

        self.assertFalse(form.is_valid())
        self.assertIn('value', form.errors)
        self.assertEqual(
            form.errors['value'],
            [six.text_type(form.fields['value'].error_messages['required'])])
Esempio n. 6
0
def contact_view(request):
    if request.method == 'POST':
        form = ContactForm(request.POST)
        if form.is_valid():
            name1 = request.POST.get('name')
            salary1 = request.POST['salary']
            email1 = form.cleaned_data['email']
            location1 = form.cleaned_data.get('location')
            data = ContactData(name=name1,
                               salary=salary1,
                               email=email1,
                               location=location1)
            data.save()
            form = ContactForm()
            return render(request, 'contact.html', {'form': form})
        else:
            return HttpResponse('<h1> Invalid Form</h1>')
    else:
        form = ContactForm()
        return render(request, 'contact.html', {'form': form})