Commit f6c1d17d authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

commenting source

parent 738607de
......@@ -21,12 +21,16 @@ def bootstrap(object):
if isinstance(object, BoundField):
field = object
attrs = field.field.widget.attrs
# get the class specified in the code
css_classes = set(attrs.get("class", "").split(" "))
# if the field has errors, we add bootstrap classes
if field.errors:
css_classes.add("is-invalid")
# we propagate the "required" attribute
if field.field.required:
attrs['required'] = 'required'
if isinstance(field.field.widget, widgets.CheckboxInput):
# if it is a checkbox, we the classes are not the same
wrapping_classes = "form-check"
label_classes = "form-check-label"
css_classes.add("form-check-input")
......@@ -35,21 +39,29 @@ def bootstrap(object):
# label_classes = "form-check-label"
# css_classes.add("form-check-input")
else:
# usual classes
wrapping_classes = "input_field form-group"
label_classes = "form-control-placeholder"
css_classes.add("form-control")
if field.name == "DELETE":
# HACK : If the field is the DELETE button of the formset
attrs["onchange"] = "formsetItemDelete(this);"
wrapping_classes += " formset-item-delete-host"
css_classes.add("formset-item-delete")
# overwrite the css classes
attrs["class"] = " ".join(css_classes)
# render the field
ret.append('<div class="%s">' % wrapping_classes)
ret.append(field.as_widget(attrs=attrs))
ret.append("""<label class="%s">%s</label>""" % (label_classes, field.label))
if field.errors:
# render its errors
for e in field.errors:
ret.append("""<div class="invalid-feedback">%s</div>""" % e)
ret.append('</div>')
# return it as safe html code
return mark_safe("".join(ret))
else:
logger.error("Can't bootstrapize object of class %s" % str(type(object)))
......
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