Skip to content

Commit

Permalink
newforms-admin: Fixed #7160 -- MultiWidget._has_changed was short-cir…
Browse files Browse the repository at this point in the history
…cuiting while testing for changed data in its widgets. Added tests to ensure this won't get broken in the future.

git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7517 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information
brosner committed May 5, 2008
1 parent be31882 commit f793f27
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 3 additions & 3 deletions django/newforms/widgets.py
Expand Up @@ -591,9 +591,9 @@ def _has_changed(self, initial, data):
else:
initial = self.decompress(initial)
for widget, initial, data in zip(self.widgets, initial, data):
if not widget._has_changed(initial, data):
return False
return True
if widget._has_changed(initial, data):
return True
return False

def format_output(self, rendered_widgets):
"""
Expand Down
13 changes: 11 additions & 2 deletions tests/regressiontests/forms/widgets.py
Expand Up @@ -963,10 +963,19 @@
u'<input id="bar_0" type="text" class="big" value="john" name="name_0" /><br /><input id="bar_1" type="text" class="small" value="lennon" name="name_1" />'
>>> w = MyMultiWidget(widgets=(TextInput(), TextInput()))
>>> w._has_changed(None, ['john', 'lennon'])
# test with no initial data
>>> w._has_changed(None, [u'john', u'lennon'])
True
>>> w._has_changed('john__lennon', ['john', 'lennon'])
# test when the data is the same as initial
>>> w._has_changed(u'john__lennon', [u'john', u'lennon'])
False
# test when the first widget's data has changed
>>> w._has_changed(u'john__lennon', [u'alfred', u'lennon'])
True
# test when the last widget's data has changed. this ensures that it is not
# short circuiting while testing the widgets.
>>> w._has_changed(u'john__lennon', [u'john', u'denver'])
True
# SplitDateTimeWidget #########################################################
Expand Down

0 comments on commit f793f27

Please sign in to comment.