2020
2121
2222class StaticFile (object ):
23-
23+ """
24+ Representing the different properties of a static file.
25+ """
2426 def __init__ (self , path ):
2527 self .path = path
2628
@@ -47,6 +49,11 @@ def collect(self, path, thread=None):
4749
4850
4951class DebugConfiguredStorage (LazyObject ):
52+ """
53+ A staticfiles storage class to be used for collecting which paths
54+ are resolved by using the {% static %} template tag (which uses the
55+ `url` method).
56+ """
5057 def _setup (self ):
5158
5259 configured_storage_cls = get_storage_class (settings .STATICFILES_STORAGE )
@@ -81,7 +88,6 @@ def title(self):
8188 def __init__ (self , * args , ** kwargs ):
8289 super (StaticFilesPanel , self ).__init__ (* args , ** kwargs )
8390 self .num_found = 0
84- self .ignore_patterns = []
8591 self ._paths = {}
8692
8793 @property
@@ -100,43 +106,63 @@ def num_used(self):
100106 @property
101107 def nav_subtitle (self ):
102108 num_used = self .num_used
103- return ungettext ("%(num_used)s file used" , "%(num_used)s files used" ,
109+ return ungettext ("%(num_used)s file used" ,
110+ "%(num_used)s files used" ,
104111 num_used ) % {'num_used' : num_used }
105112
106113 def process_request (self , request ):
107114 collector .clear_collection ()
108115
109116 def process_response (self , request , response ):
110- staticfiles_finders = SortedDict ()
117+ used_paths = collector .get_collection ()
118+ self ._paths [threading .currentThread ()] = used_paths
119+
120+ self .record_stats ({
121+ 'num_found' : self .num_found ,
122+ 'num_used' : self .num_used ,
123+ 'staticfiles' : used_paths ,
124+ 'staticfiles_apps' : self .get_staticfiles_apps (),
125+ 'staticfiles_dirs' : self .get_staticfiles_dirs (),
126+ 'staticfiles_finders' : self .get_staticfiles_finders (),
127+ })
128+
129+ def get_staticfiles_finders (self ):
130+ """
131+ Returns a sorted mapping between the finder path and the list
132+ of relative and file system paths which that finder was able
133+ to find.
134+ """
135+ finders_mapping = SortedDict ()
111136 for finder in finders .get_finders ():
112- for path , finder_storage in finder .list (self . ignore_patterns ):
137+ for path , finder_storage in finder .list ([] ):
113138 if getattr (finder_storage , 'prefix' , None ):
114139 prefixed_path = join (finder_storage .prefix , path )
115140 else :
116141 prefixed_path = path
117- finder_path = '.' .join ([finder .__class__ .__module__ ,
118- finder .__class__ .__name__ ])
142+ finder_cls = finder .__class__
143+ finder_path = '.' .join ([finder_cls .__module__ ,
144+ finder_cls .__name__ ])
119145 real_path = finder_storage .path (path )
120146 payload = (prefixed_path , real_path )
121- staticfiles_finders .setdefault (finder_path , []).append (payload )
147+ finders_mapping .setdefault (finder_path , []).append (payload )
122148 self .num_found += 1
149+ return finders_mapping
123150
151+ def get_staticfiles_dirs (self ):
152+ """
153+ Returns a list of paths to inspect for additional static files
154+ """
124155 dirs = getattr (settings , 'STATICFILES_DIRS' , ())
156+ return [normpath (d ) for d in dirs ]
125157
126- used_paths = collector .get_collection ()
127- self ._paths [threading .currentThread ()] = used_paths
128-
129- self .record_stats ({
130- 'num_found' : self .num_found ,
131- 'num_used' : self .num_used ,
132- 'staticfiles' : used_paths ,
133- 'staticfiles_apps' : self .get_static_apps (),
134- 'staticfiles_dirs' : [normpath (d ) for d in dirs ],
135- 'staticfiles_finders' : staticfiles_finders ,
136- })
137-
138- def get_static_apps (self ):
158+ def get_staticfiles_apps (self ):
159+ """
160+ Returns a list of app paths that have a static directory
161+ """
162+ apps = []
139163 for finder in finders .get_finders ():
140164 if isinstance (finder , finders .AppDirectoriesFinder ):
141- return finder .apps
142- return []
165+ for app in finder .apps :
166+ if app not in apps :
167+ apps .append (app )
168+ return apps
0 commit comments