From f6c1d17d85b1f33aa6b813369e302d1151a4d39a Mon Sep 17 00:00:00 2001
From: Bryan Brancotte <bryan.brancotte@pasteur.fr>
Date: Fri, 1 Feb 2019 15:13:29 +0100
Subject: [PATCH] commenting source

---
 ippisite/ippidb/templatetags/customtags.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/ippisite/ippidb/templatetags/customtags.py b/ippisite/ippidb/templatetags/customtags.py
index 7e4cec69..b62b0c21 100644
--- a/ippisite/ippidb/templatetags/customtags.py
+++ b/ippisite/ippidb/templatetags/customtags.py
@@ -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)))
-- 
GitLab