Commits

Mikhail Korobov  committed 4d1c156

cleanup

  • Participants
  • Parent commits b89610f

Comments (0)

Files changed (1)

File widget_tweaks/templatetags/widget_tweaks.py

 def set_data(field, data):
     return set_attr(field, 'data-' + data)
 
-# render_field tag
+
+@register.filter(name='field_type')
+def field_type(field):
+    """
+    Template filter that returns field class name (in lower case).
+    E.g. if field is CharField then {{ field|field_type }} will
+    return 'charfield'.
+    """
+    if hasattr(field, 'field') and field.field:
+        return field.field.__class__.__name__.lower()
+    return ''
+
+
+@register.filter(name='widget_type')
+def widget_type(field):
+    """
+    Template filter that returns field widget class name (in lower case).
+    E.g. if field's widget is TextInput then {{ field|widget_type }} will
+    return 'textinput'.
+    """
+    if hasattr(field, 'field') and hasattr(field.field, 'widget') and field.field.widget:
+        return field.field.widget.__class__.__name__.lower()
+    return ''
+
+
+# ======================== render_field tag ==============================
 
 ATTRIBUTE_RE = re.compile(r"""
     (?P<attr>
         for k, v in self.append_attrs:
             bounded_field = append_attr(bounded_field, '%s:%s' % (k,v.resolve(context)))
         return bounded_field
-
-@register.filter(name='field_type')
-def field_type(field):
-    """
-    Template filter that returns field class name (in lower case).
-    E.g. if field is CharField then {{ field|field_type }} will
-    return 'charfield'.
-    """
-    if hasattr(field, 'field') and field.field:
-        return field.field.__class__.__name__.lower()
-    return ''
-
-@register.filter(name='widget_type')
-def widget_type(field):
-    """
-    Template filter that returns field widget class name (in lower case).
-    E.g. if field's widget is TextInput then {{ field|widget_type }} will
-    return 'textinput'.
-    """
-    if hasattr(field, 'field') and hasattr(field.field, 'widget') and field.field.widget:
-        return field.field.widget.__class__.__name__.lower()
-    return ''