Django

Code

Changeset 7506

Show
Ignore:
Timestamp:
04/28/08 23:31:59 (2 months ago)
Author:
brosner
Message:

newforms-admin: Fixed #6964 -- Implemented FileInput?._has_changed. Before it was comparing the wrong values and causing it to trip up.

Files:

Legend:

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

    r7503 r7506  
    263263        "File widgets take data from FILES, not POST" 
    264264        return files.get(name, None) 
     265     
     266    def _has_changed(self, initial, data): 
     267        if data is None: 
     268            return False 
     269        return True 
    265270 
    266271class Textarea(Widget): 
  • django/branches/newforms-admin/tests/regressiontests/forms/widgets.py

    r7505 r7506  
    202202>>> w.render('email', 'ŠĐĆŜćşšđ', attrs={'class': 'fun'}) 
    203203u'<input type="file" class="fun" name="email" />' 
     204 
     205Test for the behavior of _has_changed for FileInput. The value of data will 
     206more than likely come from request.FILES. The value of initial data will 
     207likely be a filename stored in the database. Since its value is of no use to 
     208a FileInput it is ignored. 
     209 
     210>>> w = FileInput() 
     211 
     212# No file was uploaded and no initial data. 
     213>>> w._has_changed(u'', None) 
     214False 
     215 
     216# A file was uploaded and no initial data. 
     217>>> w._has_changed(u'', {'filename': 'resume.txt', 'content': 'My resume'}) 
     218True 
     219 
     220# A file was not uploaded, but there is initial data 
     221>>> w._has_changed(u'resume.txt', None) 
     222False 
     223 
     224# A file was uploaded and there is initial data (file identity is not dealt 
     225# with here) 
     226>>> w._has_changed('resume.txt', {'filename': 'resume.txt', 'content': 'My resume'}) 
     227True 
    204228 
    205229# Textarea Widget #############################################################