Author: claudep
Date: 2012-03-17 15:31:03 -0700 (Sat, 17 Mar 2012)
New Revision: 17765

Modified:
   django/trunk/django/views/generic/edit.py
   django/trunk/docs/ref/class-based-views.txt
   django/trunk/docs/releases/1.4.txt
   django/trunk/tests/regressiontests/generic_views/edit.py
   django/trunk/tests/regressiontests/generic_views/tests.py
Log:
Fixed #16138 -- Made FormMixin get_initial return a copy of the 'initial' class 
variable. Thanks hanson2010, [email protected] and agriffis for their 
work on the patch.

Modified: django/trunk/django/views/generic/edit.py
===================================================================
--- django/trunk/django/views/generic/edit.py   2012-03-17 22:13:20 UTC (rev 
17764)
+++ django/trunk/django/views/generic/edit.py   2012-03-17 22:31:03 UTC (rev 
17765)
@@ -19,7 +19,7 @@
         """
         Returns the initial data to use for forms on this view.
         """
-        return self.initial
+        return self.initial.copy()
 
     def get_form_class(self):
         """

Modified: django/trunk/docs/ref/class-based-views.txt
===================================================================
--- django/trunk/docs/ref/class-based-views.txt 2012-03-17 22:13:20 UTC (rev 
17764)
+++ django/trunk/docs/ref/class-based-views.txt 2012-03-17 22:31:03 UTC (rev 
17765)
@@ -431,9 +431,14 @@
 
     .. method:: get_initial()
 
-        Retrieve initial data for the form. By default, returns
+        Retrieve initial data for the form. By default, returns a copy of
         :attr:`.initial`.
 
+    .. admonition:: Changed in 1.4
+
+        In Django 1.3, this method was returning the :attr:`initial` class
+        variable itself.
+
     .. method:: get_form_class()
 
         Retrieve the form class to instantiate. By default

Modified: django/trunk/docs/releases/1.4.txt
===================================================================
--- django/trunk/docs/releases/1.4.txt  2012-03-17 22:13:20 UTC (rev 17764)
+++ django/trunk/docs/releases/1.4.txt  2012-03-17 22:31:03 UTC (rev 17765)
@@ -1107,6 +1107,15 @@
 Python-Markdown library less than 2.1, a warning is issued that the output is
 insecure.
 
+FormMixin get_initial returns an instance-specific dictionary
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In Django 1.3, the ``get_initial`` method of the
+:class:`django.views.generic.edit.FormMixin` class was returning the
+class ``initial`` dictionary. This has been fixed to return a copy of this
+dictionary, so form instances can modify their initial data without messing
+with the class variable.
+
 Features deprecated in 1.4
 ==========================
 

Modified: django/trunk/tests/regressiontests/generic_views/edit.py
===================================================================
--- django/trunk/tests/regressiontests/generic_views/edit.py    2012-03-17 
22:13:20 UTC (rev 17764)
+++ django/trunk/tests/regressiontests/generic_views/edit.py    2012-03-17 
22:31:03 UTC (rev 17765)
@@ -5,11 +5,20 @@
 from django import forms
 from django.test import TestCase
 from django.utils.unittest import expectedFailure
+from django.views.generic.edit import FormMixin
 
 from . import views
 from .models import Artist, Author
 
 
+class FormMixinTests(TestCase):
+     def test_initial_data(self):
+         """ Test instance independence of initial data dict (see #16138) """
+         initial_1 = FormMixin().get_initial()
+         initial_1['foo'] = 'bar'
+         initial_2 = FormMixin().get_initial()
+         self.assertNotEqual(initial_1, initial_2)
+
 class ModelFormMixinTests(TestCase):
     def test_get_form(self):
         form_class = views.AuthorGetQuerySetFormView().get_form_class()

Modified: django/trunk/tests/regressiontests/generic_views/tests.py
===================================================================
--- django/trunk/tests/regressiontests/generic_views/tests.py   2012-03-17 
22:13:20 UTC (rev 17764)
+++ django/trunk/tests/regressiontests/generic_views/tests.py   2012-03-17 
22:31:03 UTC (rev 17765)
@@ -5,6 +5,6 @@
     MonthArchiveViewTests, WeekArchiveViewTests, DayArchiveViewTests,
     DateDetailViewTests)
 from .detail import DetailViewTest
-from .edit import (ModelFormMixinTests, CreateViewTests, UpdateViewTests,
-    DeleteViewTests)
+from .edit import (FormMixinTests, ModelFormMixinTests, CreateViewTests,
+    UpdateViewTests, DeleteViewTests)
 from .list import ListViewTests

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to