From e0c1b40d158a661c4a5a0447501c0e22ff266453 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dylan=20A=C3=AFssi?= <dylan.aissi@collabora.com> Date: Thu, 11 Jul 2024 17:15:57 +0200 Subject: [PATCH] Disable link to the storage page if it doesn't exist MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise, it returns an 404 error. Signed-off-by: Dylan Aïssi <dylan.aissi@collabora.com> --- bin/dashboard | 10 +++++++++- templates/base.html.jinja2 | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/bin/dashboard b/bin/dashboard index 8784eba..4251769 100755 --- a/bin/dashboard +++ b/bin/dashboard @@ -116,12 +116,20 @@ def render(packaging_data, storage_data, destdir): env = jinja2.Environment( loader=jinja2.FileSystemLoader("templates/"), autoescape=True ) + + if packaging_data is not None and storage_data is not None: + both_data = True + else: + both_data = False + for html, data in ("index", packaging_data), ("storage", storage_data): if data is None: continue logging.debug(f"Generating {destdir}/{html}.html") - rendered = env.get_template(f"{html}.html.jinja2").render(**data) + rendered = env.get_template(f"{html}.html.jinja2").render( + **data, both_data=both_data + ) with open(destdir / f"{html}.html", "w") as html_file: html_file.write(rendered) diff --git a/templates/base.html.jinja2 b/templates/base.html.jinja2 index 1f7b992..05b4f4e 100644 --- a/templates/base.html.jinja2 +++ b/templates/base.html.jinja2 @@ -37,7 +37,7 @@ <div> <a href="index.html" class="text-muted">Packages</a> <span>â—</span> - <a href="storage.html" class="text-muted">Storage Usage</a> + <a href="storage.html" class="text-muted {{'btn-link disabled' if not both_data }}">Storage Usage</a> </div> </div> -- GitLab