{% load adminlte2_tags %}

<fieldset class="module aligned {{ fieldset.classes }}">
    {% if fieldset.name or fieldset.description %}
        <legend>
            {% if fieldset.name %}
                {{ fieldset.name }}
            {% endif %}

            {% if fieldset.description %}
                <small>{{ fieldset.description|safe }}</small>
            {% endif %}
        </legend>
    {% endif %}

    {% for line in fieldset %}
        <div class="form-row{% if line.fields|length_is:'1' and line.errors %} has-error{% endif %}{% if not line.has_visible_field %} hidden{% endif %}{% for field in line %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% endfor %}">

            {% if line.fields|length_is:'1' %}
                <div>{{ line.errors }}</div>
            {% endif %}

            {% for field in line %}
                <div class="{% if not line.fields|length_is:'1' and not field.is_readonly %} form-group{% elif field.is_checkbox %} checkbox{% endif %}{% if field.field.name %} field-{{ field.field.name }}{% endif %}{% if not field.is_readonly and field.errors %} has-error{% endif %}{% if field.field.is_hidden %} hidden{% endif %}">
                    {% if not line.fields|length_is:'1' and not field.is_readonly %}
                        {{ field.errors }}
                     {% endif %}

                    {% if field.is_checkbox %}
                        {{ field.field }}{{ field.label_tag }}
                    {% else %}
                        {{ field.label_tag }}
                        {% if field.is_readonly %}
                            {{ field.field|add_attr:'readonly' }}
                        {% else %}
                            {{ field.field }}
                        {% endif %}
                    {% endif %}

                    {% if field.field.help_text %}
                        <span class="help-block">{{ field.field.help_text|safe }}</span>
                    {% endif %}
                </div>
            {% endfor %}
        </div>
    {% endfor %}
</fieldset>
