This commit is contained in:
Ross
2025-12-09 12:36:18 +00:00
parent e6943ccfc7
commit 40135a282d
6 changed files with 92 additions and 8 deletions
+33 -3
View File
@@ -4279,7 +4279,7 @@ class RotaBuilder(object):
return "\n".join(timetable)
def get_worker_timetable_html(
self, include_html_tag=False, table_name="rota-table"
self, include_html_tag=False, table_name="rota-table", html_static_prefix=None
):
model = self.model
@@ -4718,13 +4718,43 @@ class RotaBuilder(object):
"""
if include_html_tag:
# html_static_prefix controls how CSS/JS are referenced:
# - If html_static_prefix is None: try to use Django STATIC_URL when running inside Django, otherwise use relative links
# - If html_static_prefix is a falsey value (e.g. empty string or False): use relative links ("timetable.css")
# - If html_static_prefix is a string: use it as the prefix (ensuring trailing slash)
static_prefix = None
if html_static_prefix is not None:
static_prefix = html_static_prefix
if static_prefix is None:
# Attempt to detect Django settings; if not present, fall back to relative links
try:
from django.conf import settings
static_prefix = getattr(settings, "STATIC_URL", "")
except Exception:
static_prefix = ""
# If a prefix is provided and not empty, ensure trailing slash
if isinstance(static_prefix, str) and static_prefix:
if not static_prefix.endswith("/"):
static_prefix = static_prefix + "/"
if static_prefix:
css_href = f"{static_prefix}timetable.css"
js_src = f"{static_prefix}timetable.js"
else:
# Relative links for standalone usage
css_href = "timetable.css"
js_src = "timetable.js"
html = f"""<html>
<head>
<link rel="stylesheet" type="text/css" href="timetable.css">
<link rel="stylesheet" type="text/css" href="{css_href}">
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.13.0/themes/base/jquery-ui.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.13.0/jquery-ui.min.js"></script>
<script src="timetable.js" defer></script>
<script src="{js_src}" defer></script>
</head>
{html}</html>"""