mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
newforms-admin: Added link to current file for file-based widgets in the admin
git-svn-id: http://code.djangoproject.com/svn/django/branches/newforms-admin@6457 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a83d1e9ceb
commit
cc1d4c06c5
@ -164,6 +164,11 @@ class BaseModelAdmin(object):
|
||||
kwargs['widget'] = widgets.AdminTimeWidget
|
||||
return db_field.formfield(**kwargs)
|
||||
|
||||
# For FileFields and ImageFields add a link to the current file.
|
||||
if isinstance(db_field, models.ImageField) or isinstance(db_field, models.FileField):
|
||||
kwargs['widget'] = widgets.AdminFileWidget
|
||||
return db_field.formfield(**kwargs)
|
||||
|
||||
# For ForeignKey or ManyToManyFields, use a special widget.
|
||||
if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)):
|
||||
if isinstance(db_field, models.ForeignKey) and db_field.name in self.raw_id_fields:
|
||||
|
@ -60,6 +60,21 @@ class AdminSplitDateTime(forms.SplitDateTimeWidget):
|
||||
return u'<p class="datetime">%s %s<br />%s %s</p>' % \
|
||||
(_('Date:'), rendered_widgets[0], _('Time:'), rendered_widgets[1])
|
||||
|
||||
class AdminFileWidget(forms.FileInput):
|
||||
"""
|
||||
A FileField Widget that shows it's current value if it has one
|
||||
"""
|
||||
def __init__(self, attrs={}):
|
||||
super(AdminFileWidget, self).__init__(attrs)
|
||||
|
||||
def render(self, name, value, attrs=None):
|
||||
from django.conf import settings
|
||||
output = []
|
||||
if value:
|
||||
output.append('Currently: <a target="_blank" href="%s%s">%s</a> <br>Change: ' % (settings.MEDIA_URL, value, value))
|
||||
output.append(super(AdminFileWidget, self).render(name, value, attrs))
|
||||
return u''.join(output)
|
||||
|
||||
class ForeignKeyRawIdWidget(forms.TextInput):
|
||||
"""
|
||||
A Widget for displaying ForeignKeys in the "raw_id" interface rather than
|
||||
|
@ -48,6 +48,8 @@ class HttpRequest(object):
|
||||
"Returns the HTTP host using the environment or request headers."
|
||||
# We try three options, in order of decreasing preference.
|
||||
host = self.META.get('HTTP_X_FORWARDED_HOST', '')
|
||||
if host:
|
||||
return host
|
||||
if 'HTTP_HOST' in self.META:
|
||||
host = self.META['HTTP_HOST']
|
||||
else:
|
||||
|
Loading…
x
Reference in New Issue
Block a user