Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[1.2.X] Fixed #14158 -- Fixed SelectMultiple._has_changed to not assu…

…me same order of data anymore. Thanks, akaariai and dmoisset.

Backport from trunk (r14887).

git-svn-id: http://code.djangoproject.com/svn/django/branches/releases/1.2.X@14907 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 49c2f23ec1b35ef2544653c1dfa93ce144160a4e 1 parent 32bf35d
Jannis Leidel authored December 13, 2010
7  django/forms/widgets.py
@@ -527,10 +527,9 @@ def _has_changed(self, initial, data):
527 527
             data = []
528 528
         if len(initial) != len(data):
529 529
             return True
530  
-        for value1, value2 in zip(initial, data):
531  
-            if force_unicode(value1) != force_unicode(value2):
532  
-                return True
533  
-        return False
  530
+        initial_set = set([force_unicode(value) for value in initial])
  531
+        data_set = set([force_unicode(value) for value in data])
  532
+        return data_set != initial_set
534 533
 
535 534
 class RadioInput(StrAndUnicode):
536 535
     """
1  tests/regressiontests/forms/tests/widgets.py
@@ -830,6 +830,7 @@ def get_choices():
830 830
         self.assertFalse(w._has_changed([1, 2], [u'1', u'2']))
831 831
         self.assertTrue(w._has_changed([1, 2], [u'1']))
832 832
         self.assertTrue(w._has_changed([1, 2], [u'1', u'3']))
  833
+        self.assertFalse(w._has_changed([2, 1], [u'1', u'2']))
833 834
 
834 835
         # Unicode choices are correctly rendered as HTML
835 836
         self.assertEqual(w.render('nums', ['ŠĐĆŽćžšđ'], choices=[('ŠĐĆŽćžšđ', 'ŠĐabcĆŽćžšđ'), ('ćžšđ', 'abcćžšđ')]), u'<ul>\n<li><label><input type="checkbox" name="nums" value="1" /> 1</label></li>\n<li><label><input type="checkbox" name="nums" value="2" /> 2</label></li>\n<li><label><input type="checkbox" name="nums" value="3" /> 3</label></li>\n<li><label><input checked="checked" type="checkbox" name="nums" value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" /> \u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</label></li>\n<li><label><input type="checkbox" name="nums" value="\u0107\u017e\u0161\u0111" /> abc\u0107\u017e\u0161\u0111</label></li>\n</ul>')

0 notes on commit 49c2f23

Please sign in to comment.
Something went wrong with that request. Please try again.