Compare commits

..

1 Commits

Author SHA1 Message Date
Peter Pfeufer
6f7dbe695c Merge branch 'custom-static-file-storage' into 'master'
Draft: [ADD] Custom Static Files Storage Class

See merge request allianceauth/allianceauth!1726
2025-05-31 22:26:35 +00:00

View File

@ -25,22 +25,6 @@ class AaManifestStaticFilesStorage(ManifestStaticFilesStorage):
Custom static files storage that ignores missing files. Custom static files storage that ignores missing files.
""" """
@classmethod
def _cleanup_name(cls, name: str) -> str:
"""
Clean up the name by removing quotes.
This method is used to ensure that the name does not contain any quotes,
which can cause issues with file paths.
:param name: The name of the static file.
:type name: str
:return: The cleaned-up name without quotes.
:rtype: str
"""
# Remove quotes from the name
return name.replace('"', "").replace("'", "")
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
""" """
Initialize the static files storage, ignoring missing files. Initialize the static files storage, ignoring missing files.
@ -55,27 +39,25 @@ class AaManifestStaticFilesStorage(ManifestStaticFilesStorage):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
def hashed_name(self, name, content=None, filename=None): def hashed_name(self, name, *args, **kwargs):
""" """
Generate a hashed name for the given static file, ignoring missing files. Generate a hashed name for the given static file, ignoring missing files.
Ignore missing files, e.g. non-existent background image referenced from css. Ignore missing files, e.g. non-existent background image referenced from css.
Returns the original filename if the referenced file doesn't exist. Returns the original filename if the referenced file doesn't exist.
:param name: The name of the static file to hash. :param name:
:type name: str :type name:
:param content: The content of the static file, if available. :param args:
:type content: bytes | None :type args:
:param filename: The original filename of the static file, if available. :param kwargs:
:type filename: str | None :type kwargs:
:return: The hashed name of the static file, or the original name if the file is missing. :return:
:rtype: str :rtype:
""" """
try: try:
clean_name = self._cleanup_name(name) return super().hashed_name(name, *args, **kwargs)
return super().hashed_name(clean_name, content, filename)
except ValueError as e: except ValueError as e:
if settings.DEBUG: if settings.DEBUG:
# In debug mode, we log the missing file message # In debug mode, we log the missing file message