Skip to content
Snippets Groups Projects
Commit 6f20d4cb authored by Bryan BRANCOTTE's avatar Bryan BRANCOTTE
Browse files

Comments

parent 1751bd25
No related branches found
No related tags found
1 merge request!1Wizard form
......@@ -20,16 +20,15 @@ def url_replace(request, field, value):
@register.filter
def bootstrap(object):
return mark_safe("".join(bootstrap_core(object)))
return mark_safe("".join(bootstrap_core(object)))
def bootstrap_core(object):
ret = []
print(type(object.field.widget))
if isinstance(object, forms.BoundField):
field = object
if isinstance(field.field.widget, forms.HiddenInput) or \
isinstance(field.field.widget, forms.SelectMultiple):
print_label = True
if isinstance(field.field.widget, forms.HiddenInput):
ret.append(field.as_widget())
if field.errors:
for e in field.errors:
......@@ -81,7 +80,9 @@ def bootstrap_core(object):
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 print_label:
# most of the use case want to print the label
ret.append("""<label class="%s">%s</label>""" % (label_classes, field.label))
# If the field has a datalist attribut the input field will suggest from it, printing the element
if datalist:
......@@ -99,18 +100,22 @@ def bootstrap_core(object):
ret.append('</div>')
# return it as safe html code
elif isinstance(object, forms.BaseFormSet):
# print formset's error which are not related to a form the formset itself
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):
# print form's error which are not related to a field but the form itself
form = object
for field in form:
for l in bootstrap_core(field):
ret.append(l)
elif isinstance(object, ErrorList):
# print errors in a bootstrap way
for error in object:
ret.append("""<div class="alert alert-danger">%s</div>""" % error.replace("\n", "<br/>"))
elif isinstance(object, Message):
# print messages in a bootstrap way
message = object
level_tag = message.level_tag
if level_tag == "error":
......@@ -129,4 +134,4 @@ def bootstrap_core(object):
@register.filter('startswith')
def startswith(text, starts):
return text.startswith(starts)
\ No newline at end of file
return text.startswith(starts)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment