c262a92c30fa99638fda6cac1067a0590e9336f9
[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             </li>'''
30     return mark_safe(template % {'errors': field.errors, 'input': field, 'label': field.label})
31
32
33 @register.filter
34 def pretty_checkbox(field):
35     return pretty_field(field, template='''
36         <li class="checkbox">
37           <span class="error">%(errors)s</span>
38           <label class="nohide">%(input)s<span class="label"> %(label)s</span></label>
39         </li>''')