Django

Code

Changeset 7515

Show
Ignore:
Timestamp:
05/05/08 12:28:34 (1 week ago)
Author:
brosner
Message:

newforms-admin: Fixed #7132 -- Added a _has_changed method to SelectMultiple? along with tests. SelectMultiple? now correctly reports when it has changed or not.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/newforms-admin/django/newforms/widgets.py

    r7506 r7515  
    402402            return data.getlist(name) 
    403403        return data.get(name, None) 
     404     
     405    def _has_changed(self, initial, data): 
     406        if initial is None: 
     407            initial = [] 
     408        if data is None: 
     409            data = [] 
     410        if len(initial) != len(data): 
     411            return True 
     412        for value1, value2 in zip(initial, data): 
     413            if force_unicode(value1) != force_unicode(value2): 
     414                return True 
     415        return False 
    404416 
    405417class RadioInput(StrAndUnicode): 
  • django/branches/newforms-admin/tests/regressiontests/forms/widgets.py

    r7506 r7515  
    612612>>> w.render('nums', ['ŠĐĆŜćşšđ'], choices=[('ŠĐĆŜćşšđ', 'ŠĐabcĆŜćşšđ'), ('ćşšđ', 'abcćşšđ')]) 
    613613u'<select multiple="multiple" name="nums">\n<option value="1">1</option>\n<option value="2">2</option>\n<option value="3">3</option>\n<option value="\u0160\u0110\u0106\u017d\u0107\u017e\u0161\u0111" selected="selected">\u0160\u0110abc\u0106\u017d\u0107\u017e\u0161\u0111</option>\n<option value="\u0107\u017e\u0161\u0111">abc\u0107\u017e\u0161\u0111</option>\n</select>' 
     614 
     615# Test the usage of _has_changed 
     616>>> w._has_changed(None, None) 
     617False 
     618>>> w._has_changed([], None) 
     619False 
     620>>> w._has_changed(None, [u'1']) 
     621True 
     622>>> w._has_changed([1, 2], [u'1', u'2']) 
     623False 
     624>>> w._has_changed([1, 2], [u'1']) 
     625True 
     626>>> w._has_changed([1, 2], [u'1', u'3']) 
     627True 
    614628 
    615629# RadioSelect Widget ########################################################## 
     
    911925</ul> 
    912926 
     927# Test the usage of _has_changed 
     928>>> w._has_changed(None, None) 
     929False 
     930>>> w._has_changed([], None) 
     931False 
     932>>> w._has_changed(None, [u'1']) 
     933True 
     934>>> w._has_changed([1, 2], [u'1', u'2']) 
     935False 
     936>>> w._has_changed([1, 2], [u'1']) 
     937True 
     938>>> w._has_changed([1, 2], [u'1', u'3']) 
     939True 
     940 
    913941# Unicode choices are correctly rendered as HTML 
    914942>>> w.render('nums', ['ŠĐĆŜćşšđ'], choices=[('ŠĐĆŜćşšđ', 'ŠĐabcĆŜćşšđ'), ('ćşšđ', 'abcćşšđ')])