{# # One or zero ModelForm with one or multiple one to many related inline formsets. # For barebone raw version, see bs_inline_formsets.htm. #} {% macro bs_inline_formsets(related_form, formsets, action, opts) -%} {% if not formsets|is_iterable -%} {{ raise('"formsets" argument should be iterable collection of formsets') }} {% endif -%} {% set wrapper_atts = { 'class': 'formsets default-padding' } -%} {% if not opts -%} {% set opts = {} -%} {% endif -%} {% if opts.class -%} {% do tpl.add_css_classes_to_dict(wrapper_atts, opts.class) -%} {% endif -%} {% if action == '' -%} {% do tpl.add_css_classes_to_dict(wrapper_atts, 'display-only') -%} {% endif -%} {% do opts.update({'table_classes': 'table table-bordered table-collapse'}) -%} {% if opts.title is defined -%} {{ opts.title }} {% endif -%} {% if caller -%} {{ caller({'ff_heading': related_form, 'opts': opts}) }} {% endif -%} {% if action != '' -%} {% if opts.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 -%} {{ render_form(request, 'related', related_form, { 'action': action, 'caller': caller, 'opts': opts, }) }} {% endif -%} {% for formset in formsets -%} {% if formset.inline_title is defined -%} {% do opts.update({'inline_title': formset.inline_title}) -%} {% else -%} {% do opts.update({'inline_title': formset.model._meta.verbose_name}) -%} {% endif -%} {% do formset.renderer.update_context({ 'action': action, 'caller': caller, 'opts': opts, 'loop': loop, }) -%} {{ formset.renderer() }} {% endfor -%} {% if opts.submit_text is defined -%} {% endif -%} {% if caller -%} {{ caller({'buttons': True}) }} {% endif -%} {% if action != '' -%} {% endif -%} {% for formset in formsets -%} {% if formset.knockout_template -%} {% endif -%} {% endfor -%} {% endmacro -%} {% if _render_ -%} {% call(kwargs) bs_inline_formsets(form, formsets, action, opts) -%} {% endcall -%} {% endif -%}