X-Git-Url: http://git.ithinksw.org/philo.git/blobdiff_plain/943e8bc4af0c11b0ace3811199e3b0844c4c3fbc..e8b51a396d27271aa8b8d06724a21dbe2f0ac895:/philo/admin/widgets.py?ds=sidebyside diff --git a/philo/admin/widgets.py b/philo/admin/widgets.py index 62a492b..3d7d64b 100644 --- a/philo/admin/widgets.py +++ b/philo/admin/widgets.py @@ -1,6 +1,7 @@ from django import forms from django.conf import settings -from django.contrib.admin.widgets import FilteredSelectMultiple, url_params_from_lookup_dict +from django.contrib.admin.widgets import url_params_from_lookup_dict +from django.utils import simplejson as json from django.utils.html import escape from django.utils.safestring import mark_safe from django.utils.text import truncate_words @@ -40,29 +41,28 @@ class ModelLookupWidget(forms.TextInput): return mark_safe(u''.join(output)) -class TagFilteredSelectMultiple(FilteredSelectMultiple): - """ - A SelectMultiple with a JavaScript filter interface. - - Note that the resulting JavaScript assumes that the jsi18n - catalog has been loaded in the page - """ +class EmbedWidget(forms.Textarea): + """A form widget with the HTML class embedding and an embedded list of content-types.""" + def __init__(self, attrs=None): + from philo.models import value_content_type_limiter + + content_types = value_content_type_limiter.classes + data = [] + + for content_type in content_types: + data.append({'app_label': content_type._meta.app_label, 'object_name': content_type._meta.object_name.lower(), 'verbose_name': unicode(content_type._meta.verbose_name)}) + + json_ = json.dumps(data) + + default_attrs = {'class': 'embedding vLargeTextField', 'data-content-types': json_ } + + if attrs: + default_attrs.update(attrs) + + super(EmbedWidget, self).__init__(default_attrs) + class Media: - js = ( - settings.ADMIN_MEDIA_PREFIX + "js/core.js", - settings.ADMIN_MEDIA_PREFIX + "js/SelectBox.js", - settings.ADMIN_MEDIA_PREFIX + "js/SelectFilter2.js", - settings.ADMIN_MEDIA_PREFIX + "js/TagCreation.js", - ) - - def render(self, name, value, attrs=None, choices=()): - if attrs is None: attrs = {} - attrs['class'] = 'selectfilter' - if self.is_stacked: attrs['class'] += 'stacked' - output = [super(FilteredSelectMultiple, self).render(name, value, attrs, choices)] - output.append(u'\n' % \ - (name, self.verbose_name.replace('"', '\\"'), int(self.is_stacked), settings.ADMIN_MEDIA_PREFIX, name)) - return mark_safe(u''.join(output)) \ No newline at end of file + css = { + 'all': ('philo/css/EmbedWidget.css',), + } + js = ('philo/js/EmbedWidget.js',)