From 3d35ac786800ddcea3b2cb59d04a29fb25636155 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Sun, 12 Dec 2010 22:57:58 +0000 Subject: [PATCH] Fixed #14158 -- Fixed SelectMultiple._has_changed to not assume same order of data anymore. Thanks, akaariai and dmoisset. git-svn-id: http://code.djangoproject.com/svn/django/trunk@14887 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/forms/widgets.py | 7 +++---- tests/regressiontests/forms/tests/widgets.py | 1 + 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 8eb5fef3e7..6ee857a9fd 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -595,10 +595,9 @@ class SelectMultiple(Select): 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): """ diff --git a/tests/regressiontests/forms/tests/widgets.py b/tests/regressiontests/forms/tests/widgets.py index e21895b121..7eda26adb8 100644 --- a/tests/regressiontests/forms/tests/widgets.py +++ b/tests/regressiontests/forms/tests/widgets.py @@ -824,6 +824,7 @@ beatle J R Ringo False""") 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'')