[FIX] Check if the CustomCSS object exists

This commit is contained in:
Peter Pfeufer 2024-08-14 13:22:23 +02:00
parent 3c2c137dad
commit 710149ec21
No known key found for this signature in database
GPG Key ID: 6051D2C6AD4EBC27

View File

@ -33,11 +33,16 @@ def custom_css_static(path: str) -> str:
except FileNotFoundError: except FileNotFoundError:
return "" return ""
else: else:
custom_css_changed = CustomCSS.objects.first().timestamp.timestamp() try:
custom_css_version = ( custom_css = CustomCSS.objects.get(pk=1)
str(custom_css_changed).replace(" ", "").replace(":", "").replace("-", "") except CustomCSS.DoesNotExist:
) # remove spaces, colons, and dashes return ""
static_url = static(path) else:
versioned_url = static_url + "?v=" + custom_css_version custom_css_changed = custom_css.timestamp.timestamp()
custom_css_version = (
str(custom_css_changed).replace(" ", "").replace(":", "").replace("-", "")
) # remove spaces, colons, and dashes
static_url = static(path)
versioned_url = static_url + "?v=" + custom_css_version
return mark_safe(f'<link rel="stylesheet" href="{versioned_url}">') return mark_safe(f'<link rel="stylesheet" href="{versioned_url}">')