From 069a6c9f22402eb05ebdb3d213232ac5e6b6fcd4 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 1 Nov 2023 20:57:28 +0000 Subject: [PATCH 1/2] Added test --- tests/test_layout.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/test_layout.py b/tests/test_layout.py index fc2f551..928b0ed 100644 --- a/tests/test_layout.py +++ b/tests/test_layout.py @@ -688,3 +688,19 @@ def test_help_text_no_escape(): else: expected = "help_text_escape.html" assert parse_form(form) == parse_expected(expected) + + +def test_tag_context(): + SampleFormSet = formset_factory(SampleForm, extra=3) + formset = SampleFormSet() + formset.helper = FormHelper() + context = { + "form": formset, + "tag": "User defined tag in context", + } + + response = render( + request=None, template_name="crispy_render_template.html", context=context + ) + + assert response.content.count(b"User defined tag in context") == 0 From 9d1284be6466bc56ac2cecd4fa68a7d1ebf9d294 Mon Sep 17 00:00:00 2001 From: David Smith Date: Wed, 1 Nov 2023 20:57:20 +0000 Subject: [PATCH 2/2] Avoided adding tag to context. "tag" can be a popular name for a queryset and therefore added to context in views. Changed tag to crispy_tag to avoid name conflicts. Refs https://github.com/django-crispy-forms/django-crispy-forms/issues/830 --- crispy_bootstrap5/templates/bootstrap5/field.html | 8 ++++---- .../templates/bootstrap5/table_inline_formset.html | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/crispy_bootstrap5/templates/bootstrap5/field.html b/crispy_bootstrap5/templates/bootstrap5/field.html index 8312e9b..bcf471a 100644 --- a/crispy_bootstrap5/templates/bootstrap5/field.html +++ b/crispy_bootstrap5/templates/bootstrap5/field.html @@ -3,13 +3,13 @@ {% if field.is_hidden %} {{ field }} {% else %} - {% if field|is_checkbox and tag != "td" %} + {% if field|is_checkbox and crispy_tag != "td" %}
{% if label_class %}
{% endif %} {% endif %} - <{% if tag %}{{ tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="mb-3{% if field|is_checkbox and form_show_labels %} form-check{% else %}{% if 'form-horizontal' in form_class %} row{% endif %}{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}"> + <{% if crispy_tag %}{{ crispy_tag }}{% else %}div{% endif %} id="div_{{ field.auto_id }}" class="mb-3{% if field|is_checkbox and form_show_labels %} form-check{% else %}{% if 'form-horizontal' in form_class %} row{% endif %}{% endif %}{% if wrapper_class %} {{ wrapper_class }}{% endif %}{% if field.css_classes %} {{ field.css_classes }}{% endif %}"> {% if field.label and not field|is_checkbox and form_show_labels %}
{% endif %} {% endif %} {% endif %} - - {% if field|is_checkbox and tag != "td" %} + + {% if field|is_checkbox and crispy_tag != "td" %} {% if label_class %}
{% endif %} diff --git a/crispy_bootstrap5/templates/bootstrap5/table_inline_formset.html b/crispy_bootstrap5/templates/bootstrap5/table_inline_formset.html index 097ebb3..e1b6a0a 100644 --- a/crispy_bootstrap5/templates/bootstrap5/table_inline_formset.html +++ b/crispy_bootstrap5/templates/bootstrap5/table_inline_formset.html @@ -33,7 +33,7 @@ {% for field in formset.empty_form %} - {% include 'bootstrap5/field.html' with tag="td" form_show_labels=False %} + {% include 'bootstrap5/field.html' with crispy_tag="td" form_show_labels=False %} {% endfor %} @@ -44,7 +44,7 @@ {% for field in form %} - {% include 'bootstrap5/field.html' with tag="td" form_show_labels=False %} + {% include 'bootstrap5/field.html' with crispy_tag="td" form_show_labels=False %} {% endfor %} {% endfor %}