mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
newforms-admin: Fixed #6964 -- Implemented FileInput._has_changed. Before it was comparing the wrong values and causing it to trip up.
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@7506 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
c9c714f0f8
commit
95dcdf473e
@ -262,6 +262,11 @@ class FileInput(Input):
|
|||||||
def value_from_datadict(self, data, files, name):
|
def value_from_datadict(self, data, files, name):
|
||||||
"File widgets take data from FILES, not POST"
|
"File widgets take data from FILES, not POST"
|
||||||
return files.get(name, None)
|
return files.get(name, None)
|
||||||
|
|
||||||
|
def _has_changed(self, initial, data):
|
||||||
|
if data is None:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
class Textarea(Widget):
|
class Textarea(Widget):
|
||||||
def __init__(self, attrs=None):
|
def __init__(self, attrs=None):
|
||||||
|
@ -202,6 +202,30 @@ u'<input type="file" class="fun" name="email" />'
|
|||||||
>>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'})
|
>>> w.render('email', 'ŠĐĆŽćžšđ', attrs={'class': 'fun'})
|
||||||
u'<input type="file" class="fun" name="email" />'
|
u'<input type="file" class="fun" name="email" />'
|
||||||
|
|
||||||
|
Test for the behavior of _has_changed for FileInput. The value of data will
|
||||||
|
more than likely come from request.FILES. The value of initial data will
|
||||||
|
likely be a filename stored in the database. Since its value is of no use to
|
||||||
|
a FileInput it is ignored.
|
||||||
|
|
||||||
|
>>> w = FileInput()
|
||||||
|
|
||||||
|
# No file was uploaded and no initial data.
|
||||||
|
>>> w._has_changed(u'', None)
|
||||||
|
False
|
||||||
|
|
||||||
|
# A file was uploaded and no initial data.
|
||||||
|
>>> w._has_changed(u'', {'filename': 'resume.txt', 'content': 'My resume'})
|
||||||
|
True
|
||||||
|
|
||||||
|
# A file was not uploaded, but there is initial data
|
||||||
|
>>> w._has_changed(u'resume.txt', None)
|
||||||
|
False
|
||||||
|
|
||||||
|
# A file was uploaded and there is initial data (file identity is not dealt
|
||||||
|
# with here)
|
||||||
|
>>> w._has_changed('resume.txt', {'filename': 'resume.txt', 'content': 'My resume'})
|
||||||
|
True
|
||||||
|
|
||||||
# Textarea Widget #############################################################
|
# Textarea Widget #############################################################
|
||||||
|
|
||||||
>>> w = Textarea()
|
>>> w = Textarea()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user