Commit 3b784bb6 authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

can call bootstrap on an entire form

parent 0881fdb6
......@@ -18,9 +18,14 @@ def url_replace(request, field, value):
@register.filter
def bootstrap(object):
return mark_safe("".join(bootstrap_core(object)))
def bootstrap_core(object):
ret = []
if isinstance(object, forms.BoundField):
field = object
if isinstance(field.field.widget, forms.HiddenInput):
return [field.as_widget(), ]
attrs = field.field.widget.attrs
# get the class specified in the code
css_classes = set(attrs.get("class", "").split(" "))
......@@ -50,6 +55,7 @@ def bootstrap(object):
if field.name == "DELETE":
# HACK : If the field is the DELETE button of the formset
attrs["onchange"] = "formsetItemDelete(this);"
field.label = ugettext("DELETE_label")
wrapping_classes += " formset-item-delete-host"
css_classes.add("formset-item-delete")
......@@ -87,10 +93,15 @@ def bootstrap(object):
formset = object
for error in formset.non_form_errors():
ret.append("""<div class="alert alert-danger">%s</div>""" % error.replace("\n", "<br/>"))
elif isinstance(object, forms.BaseForm):
form = object
for field in form:
for l in bootstrap_core(field):
ret.append(l)
else:
ret.append("""<div class="alert alert-danger">Can't bootstrapize object of class %s</div>""" %
str(type(object).__name__))
return mark_safe("".join(ret))
return ret
@register.filter('startswith')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment