Skip to content

Commit 38dc472

Browse files
committed
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
1 parent 049d490 commit 38dc472

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

django/contrib/admin/widgets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __init__(self, attrs={}):
8484

8585
def render(self, name, value, attrs=None):
8686
output = []
87-
if value:
87+
if value and hasattr(value, "url"):
8888
output.append('%s <a target="_blank" href="%s">%s</a> <br />%s ' % \
8989
(_('Currently:'), value.url, value, _('Change:')))
9090
output.append(super(AdminFileWidget, self).render(name, value, attrs))

tests/regressiontests/admin_widgets/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def __unicode__(self):
2727
__test__ = {'WIDGETS_TESTS': """
2828
>>> from datetime import datetime
2929
>>> from django.utils.html import escape, conditional_escape
30+
>>> from django.core.files.uploadedfile import SimpleUploadedFile
3031
>>> from django.contrib.admin.widgets import FilteredSelectMultiple, AdminSplitDateTime
3132
>>> from django.contrib.admin.widgets import AdminFileWidget, ForeignKeyRawIdWidget, ManyToManyRawIdWidget
3233
>>> from django.contrib.admin.widgets import RelatedFieldWidgetWrapper
@@ -54,6 +55,8 @@ def __unicode__(self):
5455
>>> w = AdminFileWidget()
5556
>>> print conditional_escape(w.render('test', album.cover_art))
5657
Currently: <a target="_blank" href="%(STORAGE_URL)salbums/hybrid_theory.jpg">albums\hybrid_theory.jpg</a> <br />Change: <input type="file" name="test" />
58+
>>> print conditional_escape(w.render('test', SimpleUploadedFile('test', 'content')))
59+
<input type="file" name="test" />
5760
5861
>>> rel = Album._meta.get_field('band').rel
5962
>>> w = ForeignKeyRawIdWidget(rel)

0 commit comments

Comments
 (0)