mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #26018 -- Prevented unecessary get_form() call in FormMixin.get_context_data().
Changed "dict.setdefault" to "if x in dict" pattern so that get_form() would not be called unnecessarily, specifically in the case where FormMixin.form_invalid() calls get_context_data() with the current form.
This commit is contained in:
parent
7bc94b58bf
commit
e429c5186c
4 changed files with 10 additions and 2 deletions
|
@ -232,6 +232,7 @@ class UpdateViewTests(TestCase):
|
|||
self.assertEqual(res.context['object'], Author.objects.get(pk=a.pk))
|
||||
self.assertEqual(res.context['author'], Author.objects.get(pk=a.pk))
|
||||
self.assertTemplateUsed(res, 'generic_views/author_form.html')
|
||||
self.assertEqual(res.context['view'].get_form_called_count, 1)
|
||||
|
||||
# Modification with both POST and PUT (browser compatible)
|
||||
res = self.client.post('/edit/author/%d/update/' % a.pk,
|
||||
|
@ -251,6 +252,7 @@ class UpdateViewTests(TestCase):
|
|||
self.assertTemplateUsed(res, 'generic_views/author_form.html')
|
||||
self.assertEqual(len(res.context['form'].errors), 1)
|
||||
self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>'])
|
||||
self.assertEqual(res.context['view'].get_form_called_count, 1)
|
||||
|
||||
def test_update_with_object_url(self):
|
||||
a = Artist.objects.create(name='Rene Magritte')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue