Пример #1
0
def create(request):
	if request.method == 'POST': # If the form has been submitted...
		form = SubmissionForm(request.POST) # A form bound to the POST data
		if form.is_valid(): # All validation rules pass
			submission = form.save()
			#subj = submission.subject
			return HttpResponseRedirect('/thanks/') # Redirect after POST
	else:
		form = SubmissionForm() # An unbound form
	return render_to_response('submissions/create.html',{'form': form}, context_instance=RequestContext(request))
    def test_login(self):
        form_data = {
            'artwork': self.artwork.id,
            'exhibition': self.exhibition.id,
        }

        # Form requires logged-in user
        form = SubmissionForm(data=form_data)
        self.assertTrue(form.is_valid())
        self.assertRaises(IntegrityError, form.save)
    def test_exhibition_required(self):
        form_data = {
            'exhibition': self.exhibition.id,
        }

        form = SubmissionForm(data=form_data)
        self.assertFalse(form.is_valid())
        self.assertRaisesRegexp(
            ValueError,
            'The Submission could not be created because the data didn\'t validate.',
            form.save)
    def test_validation(self):

        form_data = {
            'artwork': self.artwork.id,
            'exhibition': self.exhibition.id,
        }

        form = SubmissionForm(data=form_data)
        self.assertTrue(form.is_valid())
        self.assertEqual(form.instance.artwork.id, form_data['artwork'])
        self.assertEqual(form.instance.exhibition.id, form_data['exhibition'])

        # Have to set the author before we can save
        form.instance.submitted_by = self.user
        form.save()

        self.assertEqual(
            '%s' % Submission.objects.get(id=form.instance.id),
            '%s :: %s' % (self.exhibition.title, self.artwork.title)
        )