newsletter checkboxes in suggestions and registration
[wolnelektury.git] / src / ajaxable / templatetags / ajaxable_tags.py
index 351e9f1..c262a92 100644 (file)
@@ -3,6 +3,8 @@
 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
 #
 from django import template
+from django.utils.safestring import mark_safe
+
 from ajaxable.utils import placeholdized
 register = template.Library()
 
@@ -15,3 +17,23 @@ def placeholdize(form):
 @register.filter
 def placeholdized_ul(form):
     return placeholdized(form).as_ul()
+
+
+@register.filter
+def pretty_field(field, template=None):
+    if template is None:
+        template = '''
+            <li>
+              <span class="error">%(errors)s</span>
+              <label class="nohide"><span class="label">%(label)s: </span>%(input)s</label>
+            </li>'''
+    return mark_safe(template % {'errors': field.errors, 'input': field, 'label': field.label})
+
+
+@register.filter
+def pretty_checkbox(field):
+    return pretty_field(field, template='''
+        <li class="checkbox">
+          <span class="error">%(errors)s</span>
+          <label class="nohide">%(input)s<span class="label"> %(label)s</span></label>
+        </li>''')