Skip to content

Commit 7fd77d9

Browse files
committed
[deps] Switched to django-minify-compress-staticfiles #565
Replaced django-compress-staticfiles with the new django-minify-compress-staticfiles package for static file minification and compression. The new package provides: - CSS/JS minification using rjsmin and rcssmin - Both Gzip and Brotli compression support - Better security with path traversal protection - Configurable compression levels and file size limits Updated imports in storage.py and documentation references accordingly. Fixes #565
1 parent 3bf2978 commit 7fd77d9

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

openwisp_utils/storage.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88

99
class FileHashedNameMixin:
1010
default_excluded_patterns = ["leaflet/*/*.png"]
11-
excluded_patterns = default_excluded_patterns + getattr(
12-
settings, "OPENWISP_STATICFILES_VERSIONED_EXCLUDE", []
13-
)
11+
12+
@property
13+
def excluded_patterns(self):
14+
return self.default_excluded_patterns + getattr(
15+
settings, "OPENWISP_STATICFILES_VERSIONED_EXCLUDE", []
16+
)
1417

1518
def hashed_name(self, name, content=None, filename=None):
1619
if not any(

tests/test_project/tests/test_admin.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,10 @@ def test_stacked_inline_help_text(self):
292292
response, "Only added operators will have permission to access the project."
293293
)
294294
self.assertContains(response, "https://github.com/openwisp/openwisp-utils/")
295-
# Response should contain static in 'icon_url'
296-
self.assertContains(
297-
response, '<img src="/static/admin/img/icon-alert.svg">', html=True
295+
# Response should contain static icon-alert image (with or without hash)
296+
self.assertRegex(
297+
response.content.decode(),
298+
r'<img src="/static/admin/img/icon-alert(\.[a-f0-9]+)?\.svg">',
298299
)
299300

300301
def test_admin_theme_css_setting(self):
@@ -358,10 +359,10 @@ def test_admin_theme_static_backward_compatible(self):
358359
self.assertEqual(
359360
_staticfy("admin/css/openwisp.css"), "admin/css/openwisp.css"
360361
)
361-
# test static files are loaded with staticfiles
362-
self.assertEqual(
363-
_staticfy("admin/css/openwisp.css"), "/static/admin/css/openwisp.css"
364-
)
362+
# test static files are loaded with staticfiles (may include hash and .min)
363+
result = _staticfy("admin/css/openwisp.css")
364+
self.assertTrue(result.startswith("/static/admin/css/openwisp."))
365+
self.assertTrue(result.endswith(".css"))
365366

366367
def test_admin_theme_js_setting(self):
367368
# test for improper configuration : not a list

tests/test_project/tests/test_dashboard.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,13 @@ def test_index_content(self):
214214
self.assertContains(
215215
response, '<div style="display:none">Testing dashboard</div>'
216216
)
217-
self.assertContains(response, "dashboard-test.js")
218-
self.assertContains(response, "dashboard-test.css")
217+
# Check for dashboard-test files (may have hash and .min suffix)
218+
self.assertRegex(response.content.decode(), r'dashboard-test(\.[a-f0-9]+)?(\.min)?\.js')
219+
self.assertRegex(response.content.decode(), r'dashboard-test(\.[a-f0-9]+)?(\.min)?\.css')
219220
self.assertContains(response, "dashboard-test.config1")
220221
self.assertContains(response, "dashboard-test.config2")
221-
self.assertContains(response, "jquery.init.js")
222+
# Check for jquery.init (may have hash and .min suffix)
223+
self.assertRegex(response.content.decode(), r'jquery\.init(\.[a-f0-9]+)?(\.min)?\.js')
222224
self.assertContains(response, "Operator presence in projects")
223225
self.assertContains(response, "with_operator")
224226
self.assertContains(response, "without_operator")

0 commit comments

Comments
 (0)