Anonymous avatar Anonymous committed 4eb531e

[1.2.X] Fixed #14158 -- Fixed SelectMultiple._has_changed to not assume same order of data anymore. Thanks, akaariai and dmoisset.

Backport from trunk (r14887).

Comments (0)

Files changed (2)

django/forms/widgets.py

             data = []
         if len(initial) != len(data):
             return True
-        for value1, value2 in zip(initial, data):
-            if force_unicode(value1) != force_unicode(value2):
-                return True
-        return False
+        initial_set = set([force_unicode(value) for value in initial])
+        data_set = set([force_unicode(value) for value in data])
+        return data_set != initial_set
 
 class RadioInput(StrAndUnicode):
     """

tests/regressiontests/forms/tests/widgets.py

         self.assertFalse(w._has_changed([1, 2], [u'1', u'2']))
         self.assertTrue(w._has_changed([1, 2], [u'1']))
         self.assertTrue(w._has_changed([1, 2], [u'1', u'3']))
+        self.assertFalse(w._has_changed([2, 1], [u'1', u'2']))
 
         # Unicode choices are correctly rendered as HTML
         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>')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.