Coverage for website/utils/templatetags/fullstatic.py: 93.33%
13 statements
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
« prev ^ index » next coverage.py v7.6.7, created at 2025-08-14 10:31 +0000
1from django import template
2from django.conf import settings
3from django.templatetags import static
5register = template.Library()
8class FullStaticNode(static.StaticNode):
9 """Static tag that always gives an absolute url.
11 This gives an absolute url that can be used in emails,
12 even when normal static urls are relative (`/static/...`).
13 """
15 def url(self, context):
16 url = super().url(context)
18 # If the url is not absolute, add the base url.
19 if not url.startswith(("http://", "https://")): 19 ↛ 22line 19 didn't jump to line 22 because the condition on line 19 was always true
20 url = f"{settings.BASE_URL}{url}"
22 return url
25@register.tag("fullstatic")
26def do_static(parser, token):
27 return FullStaticNode.handle_token(parser, token)