Skip to content

Commit 4225671

Browse files
committed
Fix staticfiles panel to work with prefixed STATICFILES_DIRS.
Closes #503 and #507. Many thanks to Alexander Clausen (@sk1p) for the inspiration for the patch.
1 parent 9298aff commit 4225671

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

debug_toolbar/locale/en/LC_MESSAGES/django.po

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ msgid ""
66
msgstr ""
77
"Project-Id-Version: Django Debug Toolbar\n"
88
"Report-Msgid-Bugs-To: \n"
9-
"POT-Creation-Date: 2013-12-15 13:11+0100\n"
9+
"POT-Creation-Date: 2013-12-23 12:40+0100\n"
1010
"PO-Revision-Date: 2012-03-31 20:10+0000\n"
1111
"Last-Translator: \n"
1212
"Language-Team: \n"
@@ -557,6 +557,11 @@ msgid_plural "Static file paths"
557557
msgstr[0] ""
558558
msgstr[1] ""
559559

560+
#: templates/debug_toolbar/panels/staticfiles.html:8
561+
#, python-format
562+
msgid "(prefix %(prefix)s)"
563+
msgstr ""
564+
560565
#: templates/debug_toolbar/panels/staticfiles.html:12
561566
#: templates/debug_toolbar/panels/staticfiles.html:23
562567
#: templates/debug_toolbar/panels/staticfiles.html:35

debug_toolbar/panels/staticfiles.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ def get_staticfiles_dirs(self):
163163
"""
164164
Returns a list of paths to inspect for additional static files
165165
"""
166-
dirs = getattr(settings, 'STATICFILES_DIRS', ())
167-
return [normpath(d) for d in dirs]
166+
dirs = []
167+
for finder in finders.get_finders():
168+
if isinstance(finder, finders.FileSystemFinder):
169+
dirs.extend(finder.locations)
170+
return [(prefix, normpath(dir)) for prefix, dir in dirs]
168171

169172
def get_staticfiles_apps(self):
170173
"""

debug_toolbar/templates/debug_toolbar/panels/staticfiles.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<h4>{% blocktrans count staticfiles_dirs|length as dirs_count %}Static file path{% plural %}Static file paths{% endblocktrans %}</h4>
55
{% if staticfiles_dirs %}
66
<ol>
7-
{% for staticfiles_dir in staticfiles_dirs %}
8-
<li>{{ staticfiles_dir }}</li>
7+
{% for prefix, staticfiles_dir in staticfiles_dirs %}
8+
<li>{{ staticfiles_dir }}{% if prefix %} {% blocktrans %}(prefix {{ prefix }}){% endblocktrans %}{% endif %}</li>
99
{% endfor %}
1010
</ol>
1111
{% else %}

tests/panels/test_staticfiles.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import absolute_import, unicode_literals
44

5-
from django.conf import settings
5+
from django.contrib.staticfiles import finders
66

77
from ..base import BaseTestCase
88

@@ -19,10 +19,10 @@ def test_default_case(self):
1919
self.assertIn('django.contrib.staticfiles.finders.'
2020
'AppDirectoriesFinder', self.panel.content)
2121
self.assertIn('django.contrib.staticfiles.finders.'
22-
'FileSystemFinder (1 file)', self.panel.content)
22+
'FileSystemFinder (2 files)', self.panel.content)
2323
self.assertEqual(self.panel.num_used, 0)
2424
self.assertNotEqual(self.panel.num_found, 0)
2525
self.assertEqual(self.panel.get_staticfiles_apps(),
2626
['django.contrib.admin', 'debug_toolbar'])
2727
self.assertEqual(self.panel.get_staticfiles_dirs(),
28-
settings.STATICFILES_DIRS)
28+
finders.FileSystemFinder().locations)

tests/settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242

4343
STATIC_URL = '/static/'
4444

45-
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'tests', 'additional_static')]
46-
45+
STATICFILES_DIRS = [
46+
os.path.join(BASE_DIR, 'tests', 'additional_static'),
47+
("prefix", os.path.join(BASE_DIR, 'tests', 'additional_static')),
48+
]
4749

4850
# Cache and database
4951

0 commit comments

Comments
 (0)