diff --git a/cas_server/forms.py b/cas_server/forms.py index bcfaecb..54afb7f 100644 --- a/cas_server/forms.py +++ b/cas_server/forms.py @@ -26,15 +26,11 @@ class BootsrapForm(forms.Form): """ def __init__(self, *args, **kwargs): super(BootsrapForm, self).__init__(*args, **kwargs) - for (name, field) in self.fields.items(): + for field in self.fields.values(): # Only tweak the fiel if it will be displayed if not isinstance(field.widget, forms.HiddenInput): - # tell to display the field (used in form.html) - self[name].display = True attrs = {} - if isinstance(field.widget, forms.CheckboxInput): - self[name].checkbox = True - else: + if not isinstance(field.widget, forms.CheckboxInput): attrs['class'] = "form-control" if field.label: # pragma: no branch (currently all field are hidden or labeled) attrs["placeholder"] = field.label diff --git a/cas_server/templates/cas_server/form.html b/cas_server/templates/cas_server/form.html index 5ac1463..f189f6b 100644 --- a/cas_server/templates/cas_server/form.html +++ b/cas_server/templates/cas_server/form.html @@ -1,10 +1,11 @@ +{% load cas_server %} {% for error in form.non_field_errors %}
{{error}}
{% endfor %} -{% for field in form %}{% if field.display %} +{% for field in form %}{% if not field|is_hidden %}
{% spaceless %} - {% if field.checkbox %} + {% if field|is_checkbox %}
{% else %} diff --git a/cas_server/templatetags/__init__.py b/cas_server/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cas_server/templatetags/cas_server.py b/cas_server/templatetags/cas_server.py new file mode 100644 index 0000000..ec2839e --- /dev/null +++ b/cas_server/templatetags/cas_server.py @@ -0,0 +1,14 @@ +from django import template +from django import forms + +register = template.Library() + + +@register.filter(name='is_checkbox') +def is_checkbox(field): + return isinstance(field.field.widget, forms.CheckboxInput) + + +@register.filter(name='is_hidden') +def is_hidden(field): + return isinstance(field.field.widget, forms.HiddenInput)