From d05ebdb6491669faaf21d91633974d385129a951 Mon Sep 17 00:00:00 2001 From: Brian Rosner Date: Sun, 31 Aug 2008 17:20:43 +0000 Subject: [PATCH] Fixed #8058 -- Moved media for filter_vertical/filter_horizontal widget to the widget for use outside the admin. This also corrects RelatedFieldWidgetWrapper to expose the media of the wrapped widget. Thanks Erwin for the report and cgrady and ramikassab for the complete patch. git-svn-id: http://code.djangoproject.com/svn/django/trunk@8764 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/admin/options.py | 2 -- django/contrib/admin/widgets.py | 13 +++++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 4643e3590b5..62e4aaedc3c 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -203,8 +203,6 @@ class ModelAdmin(BaseModelAdmin): js.append('js/urlify.js') if self.opts.get_ordered_objects(): js.extend(['js/getElementsBySelector.js', 'js/dom-drag.js' , 'js/admin/ordering.js']) - if self.filter_vertical or self.filter_horizontal: - js.extend(['js/SelectBox.js' , 'js/SelectFilter2.js']) return forms.Media(js=['%s%s' % (settings.ADMIN_MEDIA_PREFIX, url) for url in js]) media = property(_media) diff --git a/django/contrib/admin/widgets.py b/django/contrib/admin/widgets.py index d3deada0ede..15720a792b6 100644 --- a/django/contrib/admin/widgets.py +++ b/django/contrib/admin/widgets.py @@ -17,9 +17,14 @@ class FilteredSelectMultiple(forms.SelectMultiple): """ A SelectMultiple with a JavaScript filter interface. - Note that the resulting JavaScript assumes that the SelectFilter2.js - library and its dependencies have been loaded in the HTML page. + Note that the resulting JavaScript assumes that the jsi18n + catalog has been loaded in the page """ + class Media: + js = (settings.ADMIN_MEDIA_PREFIX + "js/core.js", + settings.ADMIN_MEDIA_PREFIX + "js/SelectBox.js", + settings.ADMIN_MEDIA_PREFIX + "js/SelectFilter2.js") + def __init__(self, verbose_name, is_stacked, attrs=None, choices=()): self.verbose_name = verbose_name self.is_stacked = is_stacked @@ -182,6 +187,10 @@ class RelatedFieldWidgetWrapper(forms.Widget): memo[id(self)] = obj return obj + def _media(self): + return self.widget.media + media = property(_media) + def render(self, name, value, *args, **kwargs): rel_to = self.rel.to related_url = '../../../%s/%s/' % (rel_to._meta.app_label, rel_to._meta.object_name.lower())