Fixed #7250 -- Don't show internal data of a FileField in the admin when the form does not validate. This also alternatively fixes a recent problem since [8244] when the form is not valid. Thanks Marc Garcia for the initial ticket.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8277 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Brian Rosner 2008-08-10 01:07:40 +00:00
parent 049d490875
commit 38dc472796
2 changed files with 4 additions and 1 deletions

View File

@ -84,7 +84,7 @@ class AdminFileWidget(forms.FileInput):
def render(self, name, value, attrs=None): def render(self, name, value, attrs=None):
output = [] output = []
if value: if value and hasattr(value, "url"):
output.append('%s <a target="_blank" href="%s">%s</a> <br />%s ' % \ output.append('%s <a target="_blank" href="%s">%s</a> <br />%s ' % \
(_('Currently:'), value.url, value, _('Change:'))) (_('Currently:'), value.url, value, _('Change:')))
output.append(super(AdminFileWidget, self).render(name, value, attrs)) output.append(super(AdminFileWidget, self).render(name, value, attrs))

View File

@ -27,6 +27,7 @@ class Album(models.Model):
__test__ = {'WIDGETS_TESTS': """ __test__ = {'WIDGETS_TESTS': """
>>> from datetime import datetime >>> from datetime import datetime
>>> from django.utils.html import escape, conditional_escape >>> from django.utils.html import escape, conditional_escape
>>> from django.core.files.uploadedfile import SimpleUploadedFile
>>> from django.contrib.admin.widgets import FilteredSelectMultiple, AdminSplitDateTime >>> from django.contrib.admin.widgets import FilteredSelectMultiple, AdminSplitDateTime
>>> from django.contrib.admin.widgets import AdminFileWidget, ForeignKeyRawIdWidget, ManyToManyRawIdWidget >>> from django.contrib.admin.widgets import AdminFileWidget, ForeignKeyRawIdWidget, ManyToManyRawIdWidget
>>> from django.contrib.admin.widgets import RelatedFieldWidgetWrapper >>> from django.contrib.admin.widgets import RelatedFieldWidgetWrapper
@ -54,6 +55,8 @@ HTML escaped.
>>> w = AdminFileWidget() >>> w = AdminFileWidget()
>>> print conditional_escape(w.render('test', album.cover_art)) >>> print conditional_escape(w.render('test', album.cover_art))
Currently: <a target="_blank" href="%(STORAGE_URL)salbums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a> <br />Change: <input type="file" name="test" /> Currently: <a target="_blank" href="%(STORAGE_URL)salbums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a> <br />Change: <input type="file" name="test" />
>>> print conditional_escape(w.render('test', SimpleUploadedFile('test', 'content')))
<input type="file" name="test" />
>>> rel = Album._meta.get_field('band').rel >>> rel = Album._meta.get_field('band').rel
>>> w = ForeignKeyRawIdWidget(rel) >>> w = ForeignKeyRawIdWidget(rel)