From c12cd17b2d71694ad95702516a54bd197062fc0b Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Fri, 16 Jan 2026 13:18:35 +0100 Subject: [PATCH 1/2] Overwrite static tag to include version --- rdmo/core/templatetags/static.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 rdmo/core/templatetags/static.py diff --git a/rdmo/core/templatetags/static.py b/rdmo/core/templatetags/static.py new file mode 100644 index 0000000000..ea9454e647 --- /dev/null +++ b/rdmo/core/templatetags/static.py @@ -0,0 +1,23 @@ +from django import template +from django.conf import settings +from django.templatetags.static import static as django_static + +from rdmo import __version__ + +register = template.Library() + +@register.simple_tag +def static(path): + """ + Custom static tag that appends ?v={version} to all urls created with `{% static ... %}`. + This overwrites the original django.templatetags.static.static. + """ + static_url = django_static(path) + + if settings.DEBUG: + return static_url + else: + if '?' in static_url: + return f'{static_url}&v={__version__}' + else: + return f'{static_url}?v={__version__}' From 906bbadaa4ead4ad9b15de6f2aafa5d1ec05fd2b Mon Sep 17 00:00:00 2001 From: Jochen Klar Date: Fri, 16 Jan 2026 13:50:49 +0100 Subject: [PATCH 2/2] Use custom storage instead of static tag --- rdmo/core/settings.py | 2 ++ rdmo/core/storage.py | 18 ++++++++++++++++++ rdmo/core/templatetags/static.py | 23 ----------------------- 3 files changed, 20 insertions(+), 23 deletions(-) create mode 100644 rdmo/core/storage.py delete mode 100644 rdmo/core/templatetags/static.py diff --git a/rdmo/core/settings.py b/rdmo/core/settings.py index 237846cef6..3aa1b744c0 100644 --- a/rdmo/core/settings.py +++ b/rdmo/core/settings.py @@ -163,6 +163,8 @@ 'compressor.finders.CompressorFinder', ) +STATICFILES_STORAGE = 'rdmo.core.storage.VersionedStaticFilesStorage' + DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', diff --git a/rdmo/core/storage.py b/rdmo/core/storage.py new file mode 100644 index 0000000000..6039f1c8d4 --- /dev/null +++ b/rdmo/core/storage.py @@ -0,0 +1,18 @@ +from django.conf import settings +from django.contrib.staticfiles.storage import StaticFilesStorage + +from rdmo import __version__ + + +class VersionedStaticFilesStorage(StaticFilesStorage): + + def url(self, name): + url = super().url(name) + + if settings.DEBUG: + return url + else: + if '?' in url: + return f'{url}&v={__version__}' + else: + return f'{url}?v={__version__}' diff --git a/rdmo/core/templatetags/static.py b/rdmo/core/templatetags/static.py deleted file mode 100644 index ea9454e647..0000000000 --- a/rdmo/core/templatetags/static.py +++ /dev/null @@ -1,23 +0,0 @@ -from django import template -from django.conf import settings -from django.templatetags.static import static as django_static - -from rdmo import __version__ - -register = template.Library() - -@register.simple_tag -def static(path): - """ - Custom static tag that appends ?v={version} to all urls created with `{% static ... %}`. - This overwrites the original django.templatetags.static.static. - """ - static_url = django_static(path) - - if settings.DEBUG: - return static_url - else: - if '?' in static_url: - return f'{static_url}&v={__version__}' - else: - return f'{static_url}?v={__version__}'