{% load addcss %}
{% load form_utils %}

{% if child.errors %}
<p class="alert alert-danger alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    Please correct the error{{ child.errors|pluralize }} below.
</p>
{% endif %}

{% if child.non_field_errors %}
{% for error in child.non_field_errors %}
<p class="alert alert-danger alert-dismissable">
    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
    {{ error }}
</p>
{% endfor %}
{% endif %}
<form action="{{ child.action }}" method="{{ child.method }}" role="form">
    {% csrf_token %}
    {% if child.fieldsets %}
    {% for fieldset in child.fieldsets %}
    <fieldset class="{{ fieldset.classes }}">
        {% if fieldset.legend %}
        <legend>{{ fieldset.legend }}</legend>
        {% endif %}
        {% if fieldset.description %}
        <p class="description text-muted">{{ fieldset.description }}</p>
        {% endif %}
        {% for field in fieldset %}
        {% if field.is_hidden %}
        {{ field }}
        {% else %}
        <div class="form-group{% if field.errors|length > 0 %} has-error {% endif %} has-feedback">
            <label for='{{ field.id_for_label }}' class="control-label">{{ field.label }}</label>
            {{field|addcss:"form-control"}}
            {% if field.errors|length > 0 %}<span
                class="glyphicon glyphicon-remove form-control-feedback"></span>

            <div class="alert alert-danger">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                {% for error in field.errors %} {{ error }} {% endfor %}
            </div>
            {% endif %}
        </div>
        {% endif %}
        {% endfor %}
    </fieldset>
    {% endfor %}


    {% else %}
    {% for field in child %}
    <div class="form-group{% if field.errors|length > 0 %} has-error {% endif %} has-feedback">
        <label for='{{ field.id_for_label }}' class="control-label">{{ field.label }}</label>
        {{field|addcss:"form-control"}}
        {% if field.errors|length > 0 %}<span
            class="glyphicon glyphicon-remove form-control-feedback"></span>

        <div class="alert alert-danger">
            <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
            {% for error in field.errors %} {{ error }} {% endfor %}
        </div>
        {% endif %}
    </div>
    {% endfor %}
    {% endif %}
    <input type="submit" value="Submit" class="btn btn-default">
</form>