{# # One or zero ModelForm with one or multiple one to many related inline formsets #} {% from 'bs_form_body.htm' import bs_form_body with context %} {% macro bs_inline_formsets(related_form, formsets, action, html) -%} {% if not html.layout_classes %} {% do html.update({'layout_classes': layout_classes}) %} {% endif %} {% if formsets|get_type == 'list' %} {% if not html.class %} {% do html.update({'class': ''}) %} {% endif %} {% set table_classes = 'table table-bordered table-responsive' %}

{{ html.title }}

{% if action != '' %} {% if html.is_ajax %} {% set atts = {'data-url': action, 'class': 'ajax-form'} %} {% else %} {% set atts = {'action': action} %} {% endif %} {% do atts.update({ 'method': 'post', 'enctype': "multipart/form-data", 'role': 'form' }) %} {% endif %} {% if related_form %}
{% if action == '' %} {# DisplayText fields use tr/td #} {% endif %} {{ bs_form_body(related_form, html.layout_classes) }} {% if action == '' %}
{% endif %}
{% endif %} {% for formset in formsets %} {{ caller({'formset_begin': formset, 'html': html}) }}
{{ formset.management_form }}
{% if formset.total_error_count() %}
{% for error in formset.errors %}
{{ error }}
{% endfor %}
{% endif %} {% do html.update({'inline_title': formset.model._meta.verbose_name}) %} {% if action == '' %} {% endif %} {% for form in formset %} {{ caller({'form_begin': form, 'html': html}) }} {% set formset_index = loop.index0 %} {% if formset.can_delete %} {% if formset_index < formset.min_num %} {% do html.update({'formset_form_class': 'form-required'}) %} {% else %} {% do html.update({'formset_form_class': 'form-optional'}) %} {% endif %} {% endif %} {% include 'bs_formset_form.htm' %} {{ caller({'form_end': form, 'html': html}) }} {% endfor %} {% if action == '' %}
{% endif %} {% if formset.knockout_template %}
{% endif %}
{{ caller({'formset_end': formset, 'html': html}) }} {% endfor %} {% if html.submit_text != '' %} {% endif %} {% if caller %} {{ caller({'buttons': True}) }} {% endif %} {% if action != '' %} {% endif %} {% for formset in formsets %} {% if formset.knockout_template %} {% endif %} {% endfor %}
{% else %} {{ raise('Formset should be list of formsets') }} {% endif %} {%- endmacro %}