1
0
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:
Brian Rosner 2008-04-29 04:31:59 +00:00
parent c9c714f0f8
commit 95dcdf473e
2 changed files with 29 additions and 0 deletions

View File

@ -263,6 +263,11 @@ class FileInput(Input):
"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):
# The 'rows' and 'cols' attributes are required for HTML correctness. # The 'rows' and 'cols' attributes are required for HTML correctness.

View File

@ -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()