Django

Code

Changeset 7366

Show
Ignore:
Timestamp:
03/26/08 23:20:21 (3 months ago)
Author:
brosner
Message:

newforms-admin: Changed Widget._has_changed to *only* use an empty string when data and/or initial is None. False values were tripping up the conditional.

Files:

Legend:

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

    r7270 r7366  
    255255            initial_value = self.initial.get(name, field.initial) 
    256256            if field.widget._has_changed(initial_value, data_value): 
    257                 #print field 
    258257                return True 
    259258        return False 
  • django/branches/newforms-admin/django/newforms/widgets.py

    r7270 r7366  
    173173        # the same as an empty string, if the data or inital value we get 
    174174        # is None, replace it w/ u''. 
    175         data_value = data or u'' 
    176         initial_value = initial or u'' 
     175        if data is None: 
     176            data_value = u'' 
     177        else: 
     178            data_value = data 
     179        if initial is None: 
     180            initial_value = u'' 
     181        else: 
     182            initial_value = initial 
    177183        if force_unicode(initial_value) != force_unicode(data_value): 
    178184            return True 
  • django/branches/newforms-admin/tests/regressiontests/forms/forms.py

    r7351 r7366  
    17181718AttributeError: 'SongForm' object has no attribute 'cleaned_data' 
    17191719 
     1720If a field is not given in the data then None is returned for its data. Lets 
     1721make sure that when checking for empty_permitted that None is treated 
     1722accordingly. 
     1723 
     1724>>> data = {'artist': None, 'song': ''} 
     1725>>> form = SongForm(data, empty_permitted=True) 
     1726>>> form.is_valid() 
     1727True 
     1728 
     1729However, we *really* need to be sure we are checking for None as any data in 
     1730initial that returns False on a boolean call needs to be treated literally. 
     1731 
     1732>>> class PriceForm(Form): 
     1733...     amount = FloatField() 
     1734...     qty = IntegerField() 
     1735 
     1736>>> data = {'amount': '0.0', 'qty': ''} 
     1737>>> form = PriceForm(data, initial={'amount': 0.0}, empty_permitted=True) 
     1738>>> form.is_valid() 
     1739True 
     1740 
    17201741"""