def test_view(request): success = None if request.method == 'POST': form = TestForm(request.POST, request.FILES) if form.is_valid(): success = True else: form = TestForm() return render_to_response('testapp/test_view.html', { 'form': form, 'success': success, })
def form(request, id=None): kwargs = {} if id: kwargs.update({'instance': TestModel.objects.get(pk=id)}) obj_list = TestModel.objects.all() if request.method == 'POST': form = TestForm(request.POST, **kwargs) if form.is_valid(): form.save() return HttpResponseRedirect('/') else: form = TestForm(**kwargs) return render_to_response('testapp/form.html', dict(form=form, obj_list=obj_list), context_instance=RequestContext(request))
def form(request, id=None): kwargs = {} if id: kwargs.update({ 'instance': TestModel.objects.get(pk=id) }) obj_list = TestModel.objects.all() if request.method == 'POST': form = TestForm(request.POST, **kwargs) if form.is_valid(): form.save() return HttpResponseRedirect('/') else: form = TestForm(**kwargs) return render_to_response('testapp/form.html', dict(form=form, obj_list=obj_list), context_instance=RequestContext(request))
def test_none(self): form = TestForm({'uuid': None}) self.assertFalse(form.is_valid(), form.errors)
def test_invalid(self): form = TestForm({'uuid': 'xxx'}) self.assertFalse(form.is_valid(), form.errors)
def test_valid(self): form = TestForm({'uuid': 'IBNApQOzTHGzdjkSt6t-Jg'}) self.assertTrue(form.is_valid(), form.errors)
def test_none(self): form = TestForm({'uuid': None}) self.assertFalse(form.is_valid(), form.errors)
def test_invalid(self): form = TestForm({'uuid': 'xxx'}) self.assertFalse(form.is_valid(), form.errors)
def test_valid(self): form = TestForm({'uuid': 'IBNApQOzTHGzdjkSt6t-Jg'}) self.assertTrue(form.is_valid(), form.errors)