Updated styles to work in the original admin. Updated the javascript to overload...
[philo.git] / philo / forms / widgets.py
1 from django.forms.widgets import Textarea
2 from django.utils import simplejson as json
3
4 __all__ = ('EmbedWidget',)
5
6 class EmbedWidget(Textarea):
7         """A form widget with the HTML class embedding and an embedded list of content-types."""
8         def __init__(self, attrs=None):
9                 from philo.models import value_content_type_limiter
10                 
11                 content_types = value_content_type_limiter.classes
12                 data = []
13                 
14                 for content_type in content_types:
15                         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)})
16                 
17                 json_ = json.dumps(data)
18                 
19                 default_attrs = {'class': 'embedding vLargeTextField', 'data-content-types': json_ }
20                 
21                 if attrs:
22                         default_attrs.update(attrs)
23                         
24                 super(EmbedWidget, self).__init__(default_attrs)
25                 
26         class Media:
27                 css = {
28                         'all': ('philo/css/EmbedWidget.css',),
29                 }
30                 js = ('philo/js/EmbedWidget.js',)