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):
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 == "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"
......@@ -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("""<div class="alert alert-danger">Can't bootstrapize object of class %s</div>""" %
return mark_safe("".join(ret))
return ret
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