Author: russellm
Date: 2010-08-17 02:08:26 -0500 (Tue, 17 Aug 2010)
New Revision: 13599

Modified:
   django/branches/releases/1.2.X/AUTHORS
   django/branches/releases/1.2.X/django/db/models/base.py
   django/branches/releases/1.2.X/tests/modeltests/model_forms/tests.py
   django/branches/releases/1.2.X/tests/modeltests/validation/test_unique.py
Log:
[1.2.X] Fixed #14102 -- Ensure that fields that have been excluded from a form 
aren't included in the unique_for_* checks, either. Thanks to Travis Cline for 
the report and fix.

Backport of r13598 from trunk.

Modified: django/branches/releases/1.2.X/AUTHORS
===================================================================
--- django/branches/releases/1.2.X/AUTHORS      2010-08-17 07:07:28 UTC (rev 
13598)
+++ django/branches/releases/1.2.X/AUTHORS      2010-08-17 07:08:26 UTC (rev 
13599)
@@ -108,6 +108,7 @@
     Michal Chruszcz <[email protected]>
     Can Burak Çilingir <[email protected]>
     Ian Clelland <[email protected]>
+    Travis Cline <[email protected]>
     Russell Cloran <[email protected]>
     [email protected]
     [email protected]

Modified: django/branches/releases/1.2.X/django/db/models/base.py
===================================================================
--- django/branches/releases/1.2.X/django/db/models/base.py     2010-08-17 
07:07:28 UTC (rev 13598)
+++ django/branches/releases/1.2.X/django/db/models/base.py     2010-08-17 
07:08:26 UTC (rev 13599)
@@ -1,6 +1,5 @@
 import types
 import sys
-import os
 from itertools import izip
 import django.db.models.manager     # Imported to register signal handler.
 from django.core.exceptions import ObjectDoesNotExist, 
MultipleObjectsReturned, FieldError, ValidationError, NON_FIELD_ERRORS
@@ -16,7 +15,7 @@
 from django.utils.translation import ugettext_lazy as _
 import django.utils.copycompat as copy
 from django.utils.functional import curry, update_wrapper
-from django.utils.encoding import smart_str, force_unicode, smart_unicode
+from django.utils.encoding import smart_str, force_unicode
 from django.utils.text import get_text_list, capfirst
 from django.conf import settings
 
@@ -744,11 +743,11 @@
                     continue
                 if f.unique:
                     unique_checks.append((model_class, (name,)))
-                if f.unique_for_date:
+                if f.unique_for_date and f.unique_for_date not in exclude:
                     date_checks.append((model_class, 'date', name, 
f.unique_for_date))
-                if f.unique_for_year:
+                if f.unique_for_year and f.unique_for_year not in exclude:
                     date_checks.append((model_class, 'year', name, 
f.unique_for_year))
-                if f.unique_for_month:
+                if f.unique_for_month and f.unique_for_month not in exclude:
                     date_checks.append((model_class, 'month', name, 
f.unique_for_month))
         return unique_checks, date_checks
 

Modified: django/branches/releases/1.2.X/tests/modeltests/model_forms/tests.py
===================================================================
--- django/branches/releases/1.2.X/tests/modeltests/model_forms/tests.py        
2010-08-17 07:07:28 UTC (rev 13598)
+++ django/branches/releases/1.2.X/tests/modeltests/model_forms/tests.py        
2010-08-17 07:08:26 UTC (rev 13599)
@@ -156,6 +156,10 @@
         form = PostForm({'subtitle': "Finally", "title": "Django 1.0 is 
released",
             "slug": "Django 1.0", 'posted': '2008-09-03'}, instance=p)
         self.assertTrue(form.is_valid())
+        form = PostForm({'title': "Django 1.0 is released"})
+        self.assertFalse(form.is_valid())
+        self.assertEqual(len(form.errors), 1)
+        self.assertEqual(form.errors['posted'], [u'This field is required.'])
 
     def test_inherited_unique_for_date(self):
         p = Post.objects.create(title="Django 1.0 is released",

Modified: 
django/branches/releases/1.2.X/tests/modeltests/validation/test_unique.py
===================================================================
--- django/branches/releases/1.2.X/tests/modeltests/validation/test_unique.py   
2010-08-17 07:07:28 UTC (rev 13598)
+++ django/branches/releases/1.2.X/tests/modeltests/validation/test_unique.py   
2010-08-17 07:08:26 UTC (rev 13599)
@@ -40,6 +40,15 @@
             ), m._get_unique_checks()
         )
 
+    def test_unique_for_date_exclusion(self):
+        m = UniqueForDateModel()
+        self.assertEqual((
+            [(UniqueForDateModel, ('id',))],
+            [(UniqueForDateModel, 'year', 'count', 'end_date'),
+             (UniqueForDateModel, 'month', 'order', 'end_date')]
+            ), m._get_unique_checks(exclude='start_date')
+        )
+
 class PerformUniqueChecksTest(unittest.TestCase):
     def setUp(self):
         # Set debug to True to gain access to connection.queries.

-- 
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