Use custom templatetags instead settings custom attributes to Boundfields
As it do not work with django 1.7
This commit is contained in:
parent
15188ba186
commit
aa98096059
|
@ -26,15 +26,11 @@ class BootsrapForm(forms.Form):
|
||||||
"""
|
"""
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(BootsrapForm, self).__init__(*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
|
# Only tweak the fiel if it will be displayed
|
||||||
if not isinstance(field.widget, forms.HiddenInput):
|
if not isinstance(field.widget, forms.HiddenInput):
|
||||||
# tell to display the field (used in form.html)
|
|
||||||
self[name].display = True
|
|
||||||
attrs = {}
|
attrs = {}
|
||||||
if isinstance(field.widget, forms.CheckboxInput):
|
if not isinstance(field.widget, forms.CheckboxInput):
|
||||||
self[name].checkbox = True
|
|
||||||
else:
|
|
||||||
attrs['class'] = "form-control"
|
attrs['class'] = "form-control"
|
||||||
if field.label: # pragma: no branch (currently all field are hidden or labeled)
|
if field.label: # pragma: no branch (currently all field are hidden or labeled)
|
||||||
attrs["placeholder"] = field.label
|
attrs["placeholder"] = field.label
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
{% load cas_server %}
|
||||||
{% for error in form.non_field_errors %}
|
{% for error in form.non_field_errors %}
|
||||||
<div class="alert alert-danger alert-dismissable">
|
<div class="alert alert-danger alert-dismissable">
|
||||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
|
||||||
{{error}}
|
{{error}}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% for field in form %}{% if field.display %}
|
{% for field in form %}{% if not field|is_hidden %}
|
||||||
<div class="form-group{% spaceless %}
|
<div class="form-group{% spaceless %}
|
||||||
{% if not form.non_field_errors %}
|
{% if not form.non_field_errors %}
|
||||||
{% if field.errors %} has-error
|
{% if field.errors %} has-error
|
||||||
|
@ -12,7 +13,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% endif %}"
|
{% endif %}"
|
||||||
{% endspaceless %}>{% spaceless %}
|
{% endspaceless %}>{% spaceless %}
|
||||||
{% if field.checkbox %}
|
{% if field|is_checkbox %}
|
||||||
<div class="checkbox"><label for="{{field.auto_id}}">{{field}}{{field.label}}</label>
|
<div class="checkbox"><label for="{{field.auto_id}}">{{field}}{{field.label}}</label>
|
||||||
{% else %}
|
{% else %}
|
||||||
<label class="control-label" for="{{field.auto_id}}">{{field.label}}</label>
|
<label class="control-label" for="{{field.auto_id}}">{{field.label}}</label>
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue