1 from django.conf import settings
2 from django import forms
3 from django.utils.safestring import mark_safe
5 from sponsors import models
8 class SponsorPageWidget(forms.Textarea):
11 'http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
12 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js',
13 settings.STATIC_URL + 'sponsors/js/jquery.json.min.js',
14 settings.STATIC_URL + 'sponsors/js/footer_admin.js',
17 'all': (settings.STATIC_URL + 'sponsors/css/footer_admin.css',),
20 def render(self, name, value, attrs=None):
21 output = [super(SponsorPageWidget, self).render(name, value, attrs)]
22 sponsors = [(unicode(obj), obj.pk) for obj in models.Sponsor.objects.all()]
23 sponsors_js = ', '.join('{name: "%s", id: %d}' % sponsor for sponsor in sponsors)
24 output.append(u'<script type="text/javascript">addEvent(window, "load", function(e) {')
25 # TODO: "id_" is hard-coded here. This should instead use the correct
26 # API to determine the ID dynamically.
27 output.append(u'$("#id_%s").sponsorsFooter({sponsors: [%s]}); });</script>\n' %
29 return mark_safe(u''.join(output))