[CHANGE] Remove custom CSS file when it will be empty

This commit is contained in:
Peter Pfeufer 2024-08-14 12:58:01 +02:00
parent 3315ae7778
commit a8271c4189
No known key found for this signature in database
GPG Key ID: 6051D2C6AD4EBC27

View File

@ -3,6 +3,7 @@ Models for the custom_css app
"""
import hashlib
import os
import re
import sys
@ -61,11 +62,19 @@ class CustomCSS(SingletonModel):
self.pk = 1
if len(self.css.replace(" ", "")) > 0:
# Write the custom CSS to a file
custom_css_file = open(
f"{settings.STATIC_ROOT}allianceauth/custom-styles.css", "w+"
)
custom_css_file.write(self.compress_css())
custom_css_file.close()
else:
# Remove the custom CSS file
try:
os.remove(f"{settings.STATIC_ROOT}allianceauth/custom-styles.css")
except FileNotFoundError:
pass
super().save(*args, **kwargs)