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

generate input field with bootstrap templating along with its error(s)

parent 71539adf
{% extends "add.html" %}
{% load i18n %}
{% load customtags %}
{% block form %}
<nav>
<div class="step_nav">
......@@ -25,9 +25,7 @@
<div class="form_div">
<form action="" method="post">
{% csrf_token %}
<table>
{{ wizard.management_form }}
{{ wizard.form.errors}}
{{ wizard.form.non_field_errors}}
{% block custom_form %}{% endblock %}
......@@ -47,13 +45,12 @@
{% endfor %}
</div>
<div class="input_field form-group">
{{ wizard.form.id_source}}
{{ wizard.form.id_source|bootstrap}}
<label class="form-control-placeholder">ID</label>
</div>
</div>
{% endif %}
</table>
<input class="submit_button" type="submit" value="{% trans "Get Infos" %}"/>
<input class="submit_button" type="submit" value="{% trans 'Get Infos' %}"/>
</form>
</div>
</div>
......
import logging
from django import template
from django.forms import BoundField
from django.utils.safestring import mark_safe
register = template.Library()
logger = logging.getLogger(__name__)
@register.simple_tag
def url_replace(request, field, value):
dict_ = request.GET.copy()
dict_[field] = value
return dict_.urlencode()
@register.filter
def bootstrap(object):
if isinstance(object, BoundField):
field = object
if field.errors:
ret = []
ret.append(field.as_widget(attrs={"class": "form-control is-invalid"}))
for e in field.errors:
ret.append("""<div class="invalid-feedback">%s</div>""" % e)
return mark_safe("".join(ret))
else:
logger.error("Can't bootstrapize object of class %s" % str(type(object)))
return 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