72b9baad46e990afe10f2e40aa548f72a104f8b0
[wolnelektury.git] / src / ajaxable / templatetags / ajaxable_tags.py
1 # -*- coding: utf-8 -*-
2 # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
4 #
5 from django import template
6 from django.utils.safestring import mark_safe
7
8 from ajaxable.utils import placeholdized
9 register = template.Library()
10
11
12 @register.filter
13 def placeholdize(form):
14     return placeholdized(form)
15
16
17 @register.filter
18 def placeholdized_ul(form):
19     return placeholdized(form).as_ul()
20
21
22 @register.filter
23 def pretty_field(field, template=None):
24     if template is None:
25         template = '''
26             <li>
27               <span class="error">%(errors)s</span>
28               <label class="nohide"><span class="label">%(label)s: </span>%(input)s</label>
29               <span class="helptext">%(helptext)s</span>
30             </li>'''
31     return mark_safe(template % {
32         'errors': field.errors,
33         'input': field,
34         'label': field.label,
35         'helptext': field.help_text,
36     })
37
38
39 @register.filter
40 def pretty_checkbox(field):
41     return pretty_field(field, template='''
42         <li class="checkbox">
43           <span class="error">%(errors)s</span>
44           <label class="nohide">%(input)s<span class="label"> %(label)s</span></label>
45           <span class="helptext">%(helptext)s</span>
46         </li>''')