diff sat_website/templatetags/utils.py @ 34:9d553570cc61

add adhesion_form.html and thank_you.html
author souliane <souliane@mailoo.org>
date Tue, 27 Jan 2015 08:20:30 +0100
parents b45621706d83
children a18800261cf6
line wrap: on
line diff
--- a/sat_website/templatetags/utils.py	Tue Jan 27 08:07:15 2015 +0100
+++ b/sat_website/templatetags/utils.py	Tue Jan 27 08:20:30 2015 +0100
@@ -1,4 +1,5 @@
 from django import template
+from django.forms import RadioSelect, CheckboxInput
 register = template.Library()
 
 @register.filter
@@ -13,6 +14,36 @@
     return type(value) == tuple
 
 @register.filter
+def is_radio(value):
+    """Tell if this value is a RadioSelect or not.
+
+    @param value (obj): any object
+    @return: True if value is a RadioSelect
+    """
+    return type(value) == RadioSelect
+
+@register.filter
+def is_checkbox(value):
+    """Tell if this value is a CheckboxInput or not.
+
+    @param value (obj): any object
+    @return: True if value is a CheckboxInput
+    """
+    return type(value) == CheckboxInput
+
+@register.filter
+def selected_label(select):
+    """Return the label of the single selected option.
+    
+    @param select: a BoundField object bound to a Select with single choice.
+    @return: unicode
+    """
+    for value, label in select.field.choices:
+        if value == select.value():
+            return label
+    return None
+
+@register.filter
 def buffer(value, n):
     """Split values in sub-lists of n elements.