Ticket #6964: 6964_fileinput.diff

File 6964_fileinput.diff, 1.9 KB (added by Brian Rosner, 16 years ago)

initial fix that needs some more thought

  • django/newforms/widgets.py

    diff --git a/django/newforms/widgets.py b/django/newforms/widgets.py
    index 8965a8c..e8a4b0d 100644
    a b class FileInput(Input):  
    262262    def value_from_datadict(self, data, files, name):
    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):
    267272    def __init__(self, attrs=None):
  • tests/regressiontests/forms/widgets.py

    diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py
    index 0e69602..476179c 100644
    a b u'<input type="file" class="fun" name="email" />'  
    202202>>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'})
    203203u'<input type="file" class="fun" name="email" />'
    204204
     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(None, '')
     214False
     215
     216# TODO: need to think about this case some more.
     217>>> w._has_changed({}, '')
     218False
     219
     220# A file was uploaded and no initial data.
     221>>> w._has_changed({'filename': 'resume.txt', 'content': 'My resume'}, '')
     222True
     223
     224# A file was not uploaded, but there is initial data
     225>>> w._has_changed(None, 'resume.txt')
     226False
     227
     228# A file was uploaded and there is initial data (file identity is not dealt
     229# with here)
     230>>> w._has_changed({'filename': 'resume.txt', 'content': 'My resume'}, 'resume.txt')
     231True
     232
    205233# Textarea Widget #############################################################
    206234
    207235>>> w = Textarea()
Back to Top