
{% import 'appbuilder/general/lib.html' as lib %}

{% if form_action is defined %}
    <form action="{{form_action}}" method="post" enctype="multipart/form-data">
{% endif %}
<form class="form-vertical" role="form" id="model_form" action="" method="post" enctype="multipart/form-data">
    {{form.hidden_tag()}}

    {% if fieldsets %}
    {% for fieldset_item in fieldsets %}
        {% if fieldset_item[1].get('expanded') == None %}
            {% set expanded = True %}
        {% else %}
            {% set expanded = fieldset_item[1].get('expanded') %}
        {% endif %}
        {% call lib.accordion_tag(loop.index,fieldset_item[0], expanded) %}
                {% for item in fieldset_item[1].get('fields') %}
                        {% if item not in exclude_cols %}
                            {{ lib.render_field(form[item]) }}
                        {% endif %}
                {% endfor %}

        {% endcall %}
    {% endfor %}
    {% else %}
    <div class="well-sm">
            {% for col in include_cols %}
                {% set field = form[col] %}
                    {% if field.name not in exclude_cols %}
                            {{ lib.render_field(field) }}
                        {% endif %}
                {% endfor %}
    {% endif %}
    </div>
    {{ lib.render_form_controls() }}
</form>
