{% load widget_tweaks %}

{{ form.media }}
{% if display|default:'table' == 'table' %}
    {% for field in form.visible_fields %}
        <tr class="{% if field.errors %}danger{% endif %}">
            {% if field|field_type == 'booleanfield' %}
                <td></td>
                <td>
                    <label>
                        {% render_field field %}
                        {{ field.label }}
                    </label>
                </td>
            {% elif field|field_type == 'imagefield' or field|field_type == 'filefield' %}
                <td>
                    {{ field.label_tag }}
                </td>
                <td>
                    <div class="form-group {% if field.errors %}has-error{% endif %}">
                        {% render_field field %}
                        <p class="help-block">{{ field.help_text }}</p>
                        {% if field.errors %}
                            <ul class="help-block list-unstyled">
                                {% for error in field.errors %}
                                    <li>{{ error|escape }}</li>
                                {% endfor %}
                            </ul>
                        {% endif %}
                    </div>
                </td>
            {% elif field|field_type == 'datetimefield' %}
                <td>
                    {{ field.label_tag }}
                </td>
                <td>
                    <div class="form-group {% if field.errors %}has-error{% endif %}">
                        {% render_field field class+="form-control vDateField" autocomplete="off" %}
                        {% if field.errors %}
                            <ul class="help-block list-unstyled">
                                {% for error in field.errors %}
                                    <li>{{ error|escape }}</li>
                                {% endfor %}
                            </ul>
                        {% endif %}
                    </div>
                </td>
            {% else %}
                <td>
                    {{ field.label_tag }}
                </td>
                <td>
                    <div class="form-group {% if field.errors %}has-error{% endif %}">
                        {% render_field field class+="form-control" %}
                        {% if field.errors %}
                            <ul class="help-block list-unstyled">
                                {% for error in field.errors %}
                                    <li>{{ error|escape }}</li>
                                {% endfor %}
                            </ul>
                        {% endif %}
                    </div>
                </td>
            {% endif %}
        </tr>
    {% endfor %}
    {% for hidden in form.hidden_fields %}
        {{ hidden }}
    {% endfor %}
{% else %}
    {% for field in form %}
        {% if field|field_type == 'booleanfield' %}
            <div class="checkbox">
                <label>
                    {% render_field field %}
                    {{ field.label }}
                </label>
            </div>
            <p class="help-block">{{ field.help_text }}</p>
        {% else %}
            <div class="form-group {% if field.errors %}has-error{% endif %}">
                {{ field.label_tag }}
                {% render_field field class+="form-control" %}
                <p class="help-block">{{ field.help_text }}</p>
                {% if field.errors %}
                    <ul class="help-block list-unstyled">
                        {% for error in field.errors %}
                            <li>{{ error|escape }}</li>
                        {% endfor %}
                    </ul>
                {% endif %}
            </div>
        {% endif %}
    {% endfor %}
{% endif %}
