custom tag for rendering checkboxes
authorMaciej Tronowski <mtro@man.poznan.pl>
Fri, 27 Feb 2015 16:05:10 +0000 (17:05 +0100)
committerMaciej Tronowski <mtro@man.poznan.pl>
Fri, 27 Feb 2015 16:05:10 +0000 (17:05 +0100)
qcg/templates/qcg/tags/bootstrap_checkbox.html [new file with mode: 0644]
qcg/templatetags/qcg_utils.py

diff --git a/qcg/templates/qcg/tags/bootstrap_checkbox.html b/qcg/templates/qcg/tags/bootstrap_checkbox.html
new file mode 100644 (file)
index 0000000..a0b9926
--- /dev/null
@@ -0,0 +1,6 @@
+<div class="form-group{% if field.field.widget.is_required %} required{% endif %}">
+    <label class="{{ label_class }} control-label" for="{{ field.id_for_label }}">{{ field.label }}</label>
+    <div class="{{ field_class }}">
+        <input type="checkbox" id="{{ field.id_for_label }}" name="{{ field.html_name }}"{% if field.value %} checked{% endif %}>
+    </div>
+</div>
index 2dfe96e..a1b6b52 100644 (file)
@@ -1,6 +1,7 @@
 from datetime import datetime, timedelta
 
 from django import template
+from django.conf import settings
 from django.utils.html import format_html, format_html_join
 from django.utils.timesince import timesince
 from django.utils.timezone import now
@@ -33,3 +34,9 @@ def display_attribute(label, value):
 def get_params_as_hidden(context, *params):
     return format_html_join('\n', u'<input type="hidden" name="{}" value="{}">',
                             ((param, v) for param in params for v in context['request'].GET.getlist(param, [])))
+
+
+@register.inclusion_tag('qcg/tags/bootstrap_checkbox.html')
+def bootstrap_checkbox(field, label_class=settings.BOOTSTRAP3['horizontal_label_class'],
+                       field_class=settings.BOOTSTRAP3['horizontal_field_class']):
+    return {'field': field, 'label_class': label_class, 'field_class': field_class}