1
0
mirror of https://github.com/django/django.git synced 2025-03-13 10:50:55 +00:00

[5.1.x] Fixed #35716 -- Fixed VariableDoesNotExist when rendering admin fieldsets.

Regression in 01ed59f753139afb514170ee7f7384c155ecbc2d.

Thank you to Fábio Domingues and Marijke Luttekes for the report,
and thank you to Natalia Bidart for the review.

Backport of fd1dd767783b5a7ec1a594fcc5885e7e4178dd26 from main.
This commit is contained in:
Sarah Boyce 2024-08-29 19:01:10 +02:00
parent 26c06671d9
commit 6203965960
5 changed files with 13 additions and 3 deletions

View File

@ -47,7 +47,7 @@
{% block field_sets %} {% block field_sets %}
{% for fieldset in adminform %} {% for fieldset in adminform %}
{% include "admin/includes/fieldset.html" with heading_level=2 id_suffix=forloop.counter0 %} {% include "admin/includes/fieldset.html" with heading_level=2 prefix="fieldset" id_prefix=0 id_suffix=forloop.counter0 %}
{% endfor %} {% endfor %}
{% endblock %} {% endblock %}

View File

@ -26,7 +26,7 @@
{% with parent_counter=forloop.counter0 %} {% with parent_counter=forloop.counter0 %}
{% for fieldset in inline_admin_form %} {% for fieldset in inline_admin_form %}
{% include "admin/includes/fieldset.html" with heading_level=4 id_prefix=parent_counter id_suffix=forloop.counter0 %} {% include "admin/includes/fieldset.html" with heading_level=4 prefix=fieldset.formset.prefix id_prefix=parent_counter id_suffix=forloop.counter0 %}
{% endfor %} {% endfor %}
{% endwith %} {% endwith %}

View File

@ -1,4 +1,4 @@
{% with prefix=fieldset.formset.prefix|default:"fieldset" id_prefix=id_prefix|default:"0" id_suffix=id_suffix|default:"0" name=fieldset.name|default:""|slugify %} {% with name=fieldset.name|default:""|slugify %}
<fieldset class="module aligned {{ fieldset.classes }}"{% if name %} aria-labelledby="{{ prefix }}-{{ id_prefix}}-{{ name }}-{{ id_suffix }}-heading"{% endif %}> <fieldset class="module aligned {{ fieldset.classes }}"{% if name %} aria-labelledby="{{ prefix }}-{{ id_prefix}}-{{ name }}-{{ id_suffix }}-heading"{% endif %}>
{% if name %} {% if name %}
{% if fieldset.is_collapsible %}<details><summary>{% endif %} {% if fieldset.is_collapsible %}<details><summary>{% endif %}

View File

@ -35,3 +35,6 @@ Bugfixes
* Restored, following a regression in Django 5.1, the ability to override the * Restored, following a regression in Django 5.1, the ability to override the
timezone and role setting behavior used within the ``init_connection_state`` timezone and role setting behavior used within the ``init_connection_state``
method of the PostgreSQL backend (:ticket:`35688`). method of the PostgreSQL backend (:ticket:`35688`).
* Fixed a bug in Django 5.1 where variable lookup errors were logged when
rendering admin fieldsets (:ticket:`35716`).

View File

@ -1768,6 +1768,13 @@ class TestInlineWithFieldsets(TestDataMixin, TestCase):
def setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@override_settings(DEBUG=True)
def test_fieldset_context_fully_set(self):
url = reverse("admin:admin_inlines_photographer_add")
with self.assertRaisesMessage(AssertionError, "no logs"):
with self.assertLogs("django.template", "DEBUG"):
self.client.get(url)
def test_inline_headings(self): def test_inline_headings(self):
response = self.client.get(reverse("admin:admin_inlines_photographer_add")) response = self.client.get(reverse("admin:admin_inlines_photographer_add"))
# Page main title. # Page main title.