{% load i18n %}
{% load styling %}
{{ form.media|safe }}  
{% add_classes_to_form form %}

{% if form.non_field_errors %}
    <div class="flash">
        {% for value in form.non_field_errors %}
            <div class="message error">
                <p>{{ value }}</p>
            </div>
      {% endfor %}                    
  </div>
{% endif %}

{% if form_display_mode_table %}
    {% for field in form.hidden_fields %}
        {{ field }}
    {% endfor %}
    <tr class="{% cycle 'odd' 'even2' %}">
    {% for field in form.visible_fields %}
            <td title="{% if field.errors %}{% for error in field.errors %}{{ error }}{% if not forloop.last %} | {% endif %}{% endfor %}{% else %}{{ field.help_text }}{% endif %}">
            {% if field.errors %}<div class="flash"><div class="error">{% endif %}
              {{ field }}
            {% if field.errors %}</div></div>{% endif %}
            </td>
    {% endfor %} 
    </tr>
{% else %}
    {% for field in form.hidden_fields %}
        {{ field }}
    {% endfor %}
    
    {% for field in form.visible_fields %}
        <div class="group">
            {% if field.errors %}<div class="fieldWithErrors">{% endif %}
            <label class="label">{{ field.label_tag }}{% if field.field.required and not read_only and not form_hide_required_text %} ({% trans "required" %}){% endif %}</label>
            {% if field.errors %}<span class="error">{% for error in field.errors %}{{ error }}{% if not forloop.last %} | {% endif %}{% endfor %}</span></div>{% endif %} 
            {{ field }}
            {% if field.help_text %}<span class="description">{{ field.help_text }}</span>{% endif %}
        </div>
    {% endfor %} 
{% endif %}
