Skip to content

Commit 569528b

Browse files
authored
Fixes #2158 -- Made static file objects orderable (#2161)
#2155 introduced deduplication and sorting of static files, however the StaticFile object wasn't orderable at all.
1 parent 8ee45ed commit 569528b

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

debug_toolbar/panels/staticfiles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from debug_toolbar import panels
1212

1313

14-
@dataclass(eq=True, frozen=True)
14+
@dataclass(eq=True, frozen=True, order=True)
1515
class StaticFile:
1616
"""
1717
Representing the different properties of a static file.

tests/panels/test_staticfiles.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,25 @@ def test_insert_content(self):
6565

6666
def test_path(self):
6767
def get_response(request):
68-
# template contains one static file
6968
return render(
7069
request,
7170
"staticfiles/path.html",
72-
{"path": Path("additional_static/base.css")},
71+
{
72+
"paths": [
73+
Path("additional_static/base.css"),
74+
Path("additional_static/base.css"),
75+
Path("additional_static/base2.css"),
76+
]
77+
},
7378
)
7479

7580
self._get_response = get_response
7681
request = RequestFactory().get("/")
7782
response = self.panel.process_request(request)
7883
self.panel.generate_stats(self.request, response)
79-
self.assertEqual(self.panel.get_stats()["num_used"], 1)
80-
self.assertIn('"/static/additional_static/base.css"', self.panel.content)
84+
self.assertEqual(self.panel.get_stats()["num_used"], 2)
85+
self.assertIn('"/static/additional_static/base.css"', self.panel.content, 1)
86+
self.assertIn('"/static/additional_static/base2.css"', self.panel.content, 1)
8187

8288
def test_storage_state_preservation(self):
8389
"""Ensure the URLMixin doesn't affect storage state"""

tests/templates/staticfiles/path.html

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{% load static %}
2-
{# A single file used twice #}
3-
{% static path %}{% static path %}
1+
{% load static %}{% for path in paths %}{% static path %}{% endfor %}

0 commit comments

Comments
 (0)