annotate gpp/core/widgets.py @ 6:b6263ac72052

Use DRY principle to manage third party javascript libraries. Created script_tags template tags to generate the correct link and script tags for 3rd party libraries. The settings.py file is the only place where the full path name is specified.
author Brian Neal <bgneal@gmail.com>
date Sat, 11 Apr 2009 22:50:56 +0000
parents dbd703f7d63a
children cc8eb028def1
rev   line source
gremmie@1 1 """
gremmie@1 2 Various useful widgets for the GPP application.
gremmie@1 3 """
gremmie@1 4
gremmie@1 5 from django import forms
gremmie@1 6 from django.utils.safestring import mark_safe
gremmie@1 7 from django.core.urlresolvers import reverse
bgneal@6 8 from django.conf import settings
gremmie@1 9
gremmie@1 10
gremmie@1 11 class AutoCompleteUserInput(forms.TextInput):
gremmie@1 12 class Media:
gremmie@1 13 css = {
bgneal@6 14 'all': settings.GPP_THIRD_PARTY_CSS['jquery-autocomplete'],
gremmie@1 15 }
bgneal@6 16 js = settings.GPP_THIRD_PARTY_JS['jquery-autocomplete']
gremmie@1 17
gremmie@1 18 def render(self, name, value, attrs=None):
gremmie@1 19 url = reverse('messages-ajax_users')
gremmie@1 20 output = super(AutoCompleteUserInput, self).render(name, value, attrs)
gremmie@1 21 return output + mark_safe(u'''\
gremmie@1 22 <script type="text/javascript">
gremmie@1 23 jQuery("#id_%s").autocomplete("%s", {
gremmie@1 24 width: 150,
gremmie@1 25 max: 10,
gremmie@1 26 highlight: false,
gremmie@1 27 multiple: false,
gremmie@1 28 scroll: true,
gremmie@1 29 scrollHeight: 300,
gremmie@1 30 matchContains: true,
gremmie@1 31 autoFill: true,
gremmie@1 32 });
gremmie@1 33 </script>''' % (name, url))
gremmie@1 34
gremmie@1 35
gremmie@1 36 # vim: ts=4 sw=4