summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorAndrew Godwin2022-12-12 07:32:35 -0700
committerAndrew Godwin2022-12-12 11:56:49 -0700
commit5bc9ff39ac4f4a4b0d43066bce9cfde0397f3388 (patch)
tree4d4403c9f9c4d41c4db5d28e5a629056051aad0c /core
parent8ffe4bc1453660c1f211496074ebcc68c924327e (diff)
downloadtakahe-5bc9ff39ac4f4a4b0d43066bce9cfde0397f3388.tar.gz
takahe-5bc9ff39ac4f4a4b0d43066bce9cfde0397f3388.tar.bz2
takahe-5bc9ff39ac4f4a4b0d43066bce9cfde0397f3388.zip
Fix static file URLs
Diffstat (limited to 'core')
-rw-r--r--core/uris.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/core/uris.py b/core/uris.py
index 9ed2a32..2800fd4 100644
--- a/core/uris.py
+++ b/core/uris.py
@@ -1,6 +1,7 @@
from urllib.parse import urljoin
from django.conf import settings
+from django.templatetags.static import static
class RelativeAbsoluteUrl:
@@ -32,3 +33,18 @@ class AutoAbsoluteUrl(RelativeAbsoluteUrl):
else:
absolute_prefix = f"https://{settings.MAIN_DOMAIN}/"
self.absolute = urljoin(absolute_prefix, self.relative)
+
+
+class StaticAbsoluteUrl(RelativeAbsoluteUrl):
+ """
+ Creates static URLs given only the static-relative path
+ """
+
+ def __init__(self, path: str):
+ static_url = static(path)
+ if "://" in static_url:
+ super().__init__(static_url)
+ else:
+ super().__init__(
+ urljoin(f"https://{settings.MAIN_DOMAIN}/", static_url), static_url
+ )