Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #7250 -- Don't show internal data of a FileField in the admin w…

…hen 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
  • Loading branch information...
commit 38dc472796eb4560d6408f4f2fd94298738794d1 1 parent 049d490
@brosner brosner authored
View
2  django/contrib/admin/widgets.py
@@ -84,7 +84,7 @@ def __init__(self, attrs={}):
def render(self, name, value, attrs=None):
output = []
- if value:
+ if value and hasattr(value, "url"):
output.append('%s <a target="_blank" href="%s">%s</a> <br />%s ' % \
(_('Currently:'), value.url, value, _('Change:')))
output.append(super(AdminFileWidget, self).render(name, value, attrs))
View
3  tests/regressiontests/admin_widgets/models.py
@@ -27,6 +27,7 @@ def __unicode__(self):
__test__ = {'WIDGETS_TESTS': """
>>> from datetime import datetime
>>> 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 AdminFileWidget, ForeignKeyRawIdWidget, ManyToManyRawIdWidget
>>> from django.contrib.admin.widgets import RelatedFieldWidgetWrapper
@@ -54,6 +55,8 @@ def __unicode__(self):
>>> w = AdminFileWidget()
>>> 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" />
+>>> print conditional_escape(w.render('test', SimpleUploadedFile('test', 'content')))
+<input type="file" name="test" />
>>> rel = Album._meta.get_field('band').rel
>>> w = ForeignKeyRawIdWidget(rel)
Please sign in to comment.
Something went wrong with that request. Please try again.