1 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 from django.conf import settings
5 from django import forms
6 from django.utils.safestring import mark_safe
8 from sponsors import models
11 class SponsorPageWidget(forms.Textarea):
14 '//ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js',
15 '//ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js',
16 settings.STATIC_URL + 'sponsors/js/jquery.json.min.js',
17 settings.STATIC_URL + 'sponsors/js/footer_admin.js',
20 'all': (settings.STATIC_URL + 'sponsors/css/footer_admin.css',),
23 def render(self, name, value, attrs=None, renderer=None):
24 output = [super(SponsorPageWidget, self).render(name, value, attrs, renderer)]
25 sponsors = [(str(obj), obj.pk, obj.logo.url) for obj in models.Sponsor.objects.all().iterator()]
26 sponsors_js = ', '.join('{name: "%s", id: %d, image: "%s"}' % sponsor for sponsor in sponsors)
27 output.append('<script type="text/javascript">$(function(e) {')
28 # TODO: "id_" is hard-coded here. This should instead use the correct
29 # API to determine the ID dynamically.
30 output.append('$("#id_%s").sponsorsFooter({sponsors: [%s]}); });</script>\n' % (name, sponsors_js))
31 return mark_safe(''.join(output))