Skip to content

Commit 9046ecc

Browse files
committed
Handle non-string template variables in TemplatesPanel
Don't need to sort the context layers are dict objects are comparable. Fixes #1317
1 parent 677a3e2 commit 9046ecc

File tree

4 files changed

+26
-4
lines changed

4 files changed

+26
-4
lines changed

debug_toolbar/panels/templates/panel.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ def _store_template_info(self, sender, **kwargs):
8888
for context_layer in context.dicts:
8989
if hasattr(context_layer, "items") and context_layer:
9090
# Check if the layer is in the cache.
91-
key_values = sorted(context_layer.items())
9291
pformatted = None
93-
for _key_values, _pformatted in self.pformat_layers:
94-
if _key_values == key_values:
92+
for key_values, _pformatted in self.pformat_layers:
93+
if key_values == context_layer:
9594
pformatted = _pformatted
9695
break
9796

@@ -133,7 +132,7 @@ def _store_template_info(self, sender, **kwargs):
133132
finally:
134133
recording(True)
135134
pformatted = pformat(temp_layer)
136-
self.pformat_layers.append((key_values, pformatted))
135+
self.pformat_layers.append((context_layer, pformatted))
137136
context_list.append(pformatted)
138137

139138
kwargs["context"] = context_list
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{% extends 'base.html' %}

tests/test_integration.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import unittest
44

5+
import django
56
import html5lib
67
from django.contrib.staticfiles.testing import StaticLiveServerTestCase
78
from django.core import signing
@@ -319,6 +320,25 @@ def test_server_timing_headers(self):
319320
for expected in expected_partials:
320321
self.assertTrue(re.compile(expected).search(server_timing))
321322

323+
def test_auth_login_view_without_redirect(self):
324+
response = self.client.get("/login_without_redirect/")
325+
self.assertEqual(response.status_code, 200)
326+
parser = html5lib.HTMLParser()
327+
doc = parser.parse(response.content)
328+
el = doc.find(".//*[@id='djDebug']")
329+
store_id = el.attrib["data-store-id"]
330+
response = self.client.get(
331+
"/__debug__/render_panel/",
332+
{"store_id": store_id, "panel_id": "TemplatesPanel"},
333+
)
334+
self.assertEqual(response.status_code, 200)
335+
# The key None (without quotes) exists in the list of template
336+
# variables.
337+
if django.VERSION < (3, 0):
338+
self.assertIn("None: &#39;&#39;", response.json()["content"])
339+
else:
340+
self.assertIn("None: &#x27;&#x27;", response.json()["content"])
341+
322342

323343
@unittest.skipIf(webdriver is None, "selenium isn't installed")
324344
@unittest.skipUnless(

tests/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from django.contrib.auth.views import LoginView
12
from django.urls import include, path, re_path
23

34
import debug_toolbar
@@ -20,5 +21,6 @@
2021
path("cached_view/", views.cached_view),
2122
path("json_view/", views.json_view),
2223
path("redirect/", views.redirect_view),
24+
path("login_without_redirect/", LoginView.as_view(redirect_field_name=None)),
2325
path("__debug__/", include(debug_toolbar.urls)),
2426
]

0 commit comments

Comments
 (0)