From 3496143962a061c980875a7cc35d33f2cdca7b3d Mon Sep 17 00:00:00 2001 From: Gregoo Date: Sat, 8 Feb 2025 10:15:54 +0100 Subject: [PATCH 1/3] Fix None being submitted to a metadata get() --- bricktracker/metadata_list.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bricktracker/metadata_list.py b/bricktracker/metadata_list.py index 44bf18f..13b9629 100644 --- a/bricktracker/metadata_list.py +++ b/bricktracker/metadata_list.py @@ -3,7 +3,7 @@ from typing import List, overload, Self, Type, TypeVar from flask import url_for -from .exceptions import NotFoundException +from .exceptions import ErrorException, NotFoundException from .fields import BrickRecordFields from .record_list import BrickRecordList from .set_owner import BrickSetOwner @@ -113,12 +113,17 @@ class BrickMetadataList(BrickRecordList[T]): # Grab a specific status @classmethod - def get(cls, id: str, /, *, allow_none: bool = False) -> T: + def get(cls, id: str | None, /, *, allow_none: bool = False) -> T: new = cls.new() - if allow_none and id == '': + if allow_none and (id == '' or id is None): return new.model() + if id is None: + raise ErrorException('Cannot get {kind} with no ID'.format( + kind=new.kind.capitalize() + )) + if id not in new.mapping: raise NotFoundException( '{kind} with ID {id} was not found in the database'.format( From bb05fbdd221f5ed4686c1bb85d5082278e66fb42 Mon Sep 17 00:00:00 2001 From: Gregoo Date: Sat, 8 Feb 2025 10:27:55 +0100 Subject: [PATCH 2/3] Warn users if there is no metadata configured --- bricktracker/views/admin/admin.py | 2 + templates/add.html | 111 ++++++++++++++++-------------- 2 files changed, 61 insertions(+), 52 deletions(-) diff --git a/bricktracker/views/admin/admin.py b/bricktracker/views/admin/admin.py index 749b3df..9835548 100644 --- a/bricktracker/views/admin/admin.py +++ b/bricktracker/views/admin/admin.py @@ -84,6 +84,7 @@ def admin() -> str: open_image = request.args.get('open_image', None) open_instructions = request.args.get('open_instructions', None) open_logout = request.args.get('open_logout', None) + open_metadata = request.args.get('open_metadata', None) open_owner = request.args.get('open_owner', None) open_purchase_location = request.args.get('open_purchase_location', None) open_retired = request.args.get('open_retired', None) @@ -93,6 +94,7 @@ def admin() -> str: open_theme = request.args.get('open_theme', None) open_metadata = ( + open_metadata or open_owner or open_purchase_location or open_status or diff --git a/templates/add.html b/templates/add.html index d9a9462..368424e 100644 --- a/templates/add.html +++ b/templates/add.html @@ -37,59 +37,66 @@
Metadata
- {% if brickset_owners | length %} - {{ accordion.header('Owners', 'owners', 'metadata', icon='user-line') }} -
- {% for owner in brickset_owners %} - {% with id=owner.as_dataset() %} -
- - -
- {% endwith %} - {% endfor %} + {% if not (brickset_owners | length) and not (brickset_purchase_locations | length) and not (brickset_storages | length) and not (brickset_tags | length) %} + - {{ accordion.footer() }} - {% endif %} - {% if brickset_purchase_locations | length %} - {{ accordion.header('Purchase location', 'purchase-location', 'metadata', icon='building-line') }} - -
- -
- {{ accordion.footer() }} - {% endif %} - {% if brickset_storages | length %} - {{ accordion.header('Storage', 'storage', 'metadata', icon='archive-2-line') }} - -
- -
- {{ accordion.footer() }} - {% endif %} - {% if brickset_tags | length %} - {{ accordion.header('Tags', 'tags', 'metadata', icon='price-tag-2-line') }} -
- {% for tag in brickset_tags %} - {% with id=tag.as_dataset() %} -
- - -
- {% endwith %} - {% endfor %} -
- {{ accordion.footer() }} + {% else %} + {% if brickset_owners | length %} + {{ accordion.header('Owners', 'owners', 'metadata', icon='user-line') }} +
+ {% for owner in brickset_owners %} + {% with id=owner.as_dataset() %} +
+ + +
+ {% endwith %} + {% endfor %} +
+ {{ accordion.footer() }} + {% endif %} + {% if brickset_purchase_locations | length %} + {{ accordion.header('Purchase location', 'purchase-location', 'metadata', icon='building-line') }} + +
+ +
+ {{ accordion.footer() }} + {% endif %} + {% if brickset_storages | length %} + {{ accordion.header('Storage', 'storage', 'metadata', icon='archive-2-line') }} + +
+ +
+ {{ accordion.footer() }} + {% endif %} + {% if brickset_tags | length %} + {{ accordion.header('Tags', 'tags', 'metadata', icon='price-tag-2-line') }} +
+ {% for tag in brickset_tags %} + {% with id=tag.as_dataset() %} +
+ + +
+ {% endwith %} + {% endfor %} +
+ {{ accordion.footer() }} + {% endif %} {% endif %}

From 1dee03fbea088c646ca2de542d0523898ffd45f4 Mon Sep 17 00:00:00 2001 From: Gregoo Date: Sat, 8 Feb 2025 10:29:08 +0100 Subject: [PATCH 3/3] Update changelog and version --- CHANGELOG.md | 4 ++++ bricktracker/version.py | 2 +- compose.legacy.yml | 2 +- compose.yaml | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b8f0bad..6840795 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 1.2.1: + +This release fixes a bug where you could not add a set if no metadata was configured. + ## 1.2.0: > **Warning** diff --git a/bricktracker/version.py b/bricktracker/version.py index 4efb1e6..30a339d 100644 --- a/bricktracker/version.py +++ b/bricktracker/version.py @@ -1,4 +1,4 @@ from typing import Final -__version__: Final[str] = '1.2.0' +__version__: Final[str] = '1.2.1' __database_version__: Final[int] = 15 diff --git a/compose.legacy.yml b/compose.legacy.yml index 2d48e3b..b6125a9 100644 --- a/compose.legacy.yml +++ b/compose.legacy.yml @@ -2,7 +2,7 @@ services: bricktracker: container_name: BrickTracker restart: unless-stopped - image: gitea.baerentsen.space/frederikbaerentsen/bricktracker:1.2.0 + image: gitea.baerentsen.space/frederikbaerentsen/bricktracker:1.2.1 ports: - "3333:3333" volumes: diff --git a/compose.yaml b/compose.yaml index 6c38ed9..06be916 100644 --- a/compose.yaml +++ b/compose.yaml @@ -2,7 +2,7 @@ services: bricktracker: container_name: BrickTracker restart: unless-stopped - image: gitea.baerentsen.space/frederikbaerentsen/bricktracker:1.2.0 + image: gitea.baerentsen.space/frederikbaerentsen/bricktracker:1.2.1 ports: - "3333:3333" volumes: