File tree Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Expand file tree Collapse file tree 3 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -17,17 +17,18 @@ class StaticFile:
1717 Representing the different properties of a static file.
1818 """
1919
20- def __init__ (self , path ):
20+ def __init__ (self , * , path , url ):
2121 self .path = path
22+ self ._url = url
2223
2324 def __str__ (self ):
24- return str ( self .path )
25+ return self .path
2526
2627 def real_path (self ):
2728 return finders .find (self .path )
2829
2930 def url (self ):
30- return storage . staticfiles_storage . url ( self .path )
31+ return self ._url
3132
3233
3334# This will record and map the StaticFile instances with its associated
@@ -58,6 +59,7 @@ def _setup(self):
5859
5960 class DebugStaticFilesStorage (configured_storage_cls ):
6061 def url (self , path ):
62+ url = super ().url (path )
6163 with contextlib .suppress (LookupError ):
6264 # For LookupError:
6365 # The ContextVar wasn't set yet. Since the toolbar wasn't properly
@@ -66,10 +68,10 @@ def url(self, path):
6668 request_id = request_id_context_var .get ()
6769 record_static_file_signal .send (
6870 sender = self ,
69- staticfile = StaticFile (path ),
71+ staticfile = StaticFile (path = str ( path ), url = url ),
7072 request_id = request_id ,
7173 )
72- return super (). url ( path )
74+ return url
7375
7476 self ._wrapped = DebugStaticFilesStorage ()
7577
Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+
13from django .conf import settings
24from django .contrib .staticfiles import finders
35from django .shortcuts import render
4- from django .test import AsyncRequestFactory
6+ from django .test import AsyncRequestFactory , RequestFactory
57
68from ..base import BaseTestCase
79
@@ -58,3 +60,19 @@ def test_insert_content(self):
5860 "django.contrib.staticfiles.finders.AppDirectoriesFinder" , content
5961 )
6062 self .assertValidHTML (content )
63+
64+ def test_path (self ):
65+ def get_response (request ):
66+ # template contains one static file
67+ return render (
68+ request ,
69+ "staticfiles/path.html" ,
70+ {"path" : Path ("additional_static/base.css" )},
71+ )
72+
73+ self ._get_response = get_response
74+ request = RequestFactory ().get ("/" )
75+ response = self .panel .process_request (request )
76+ self .panel .generate_stats (self .request , response )
77+ self .assertEqual (self .panel .num_used , 1 )
78+ self .assertIn ('"/static/additional_static/base.css"' , self .panel .content )
Original file line number Diff line number Diff line change 1+ {% load static %}{% static path %}
You can’t perform that action at this time.
0 commit comments