From 3d660c594be621a1b3b24ed5a8310b39bdde7b7f Mon Sep 17 00:00:00 2001
From: Gregoo
Date: Tue, 4 Feb 2025 10:47:22 +0100
Subject: [PATCH] Make instructions failsafe in the admin
---
bricktracker/views/admin/admin.py | 5 +++-
templates/admin/instructions.html | 40 ++++++++++++++++---------------
2 files changed, 25 insertions(+), 20 deletions(-)
diff --git a/bricktracker/views/admin/admin.py b/bricktracker/views/admin/admin.py
index 584a359..bb6a5e6 100644
--- a/bricktracker/views/admin/admin.py
+++ b/bricktracker/views/admin/admin.py
@@ -34,6 +34,7 @@ def admin() -> str:
database_exception: Exception | None = None
database_upgrade_needed: bool = False
database_version: int = -1
+ instructions: BrickInstructionsList | None = None
metadata_owners: list[BrickSetOwner] = []
metadata_statuses: list[BrickSetStatus] = []
metadata_storages: list[BrickSetStorage] = []
@@ -50,6 +51,8 @@ def admin() -> str:
database_version = database.version
database_counters = BrickSQL().count_records()
+ instructions = BrickInstructionsList()
+
metadata_owners = BrickSetOwnerList.list()
metadata_statuses = BrickSetStatusList.list(all=True)
metadata_storages = BrickSetStorageList.list()
@@ -104,7 +107,7 @@ def admin() -> str:
database_exception=database_exception,
database_upgrade_needed=database_upgrade_needed,
database_version=database_version,
- instructions=BrickInstructionsList(),
+ instructions=instructions,
metadata_owners=metadata_owners,
metadata_statuses=metadata_statuses,
metadata_storages=metadata_storages,
diff --git a/templates/admin/instructions.html b/templates/admin/instructions.html
index 99fbe5e..997348c 100644
--- a/templates/admin/instructions.html
+++ b/templates/admin/instructions.html
@@ -6,25 +6,27 @@
The instructions files folder is: {{ config['INSTRUCTIONS_FOLDER'] }}
.
Allowed file formats for instructions are the following: {{ ', '.join(config['INSTRUCTIONS_ALLOWED_EXTENSIONS']) }}
.
-Counters
-
-
-
- -
- Sets {{ instructions.sets | length }}
-
- -
- Instructions for sets {{ instructions.sets_total }}
-
- -
- Unknown {{ instructions.unknown_total }}
-
- -
- Rejected files {{ instructions.rejected_total }}
-
-
-
-
+{% if instructions %}
+ Counters
+
+
+
+ -
+ Sets {{ instructions.sets | length }}
+
+ -
+ Instructions for sets {{ instructions.sets_total }}
+
+ -
+ Unknown {{ instructions.unknown_total }}
+
+ -
+ Rejected files {{ instructions.rejected_total }}
+
+
+
+
+{% endif %}
Refresh
Refresh the instructions cache