Merge pull request '1.2.1: Fix add set with no metadata' (#63) from gregoo/BrickTracker:master into master

Reviewed-on: FrederikBaerentsen/BrickTracker#63
This commit is contained in:
FrederikBaerentsen 2025-02-08 10:49:06 +01:00
commit 6d70dbdf8b
7 changed files with 76 additions and 58 deletions

View File

@ -1,5 +1,9 @@
# Changelog # Changelog
## 1.2.1:
This release fixes a bug where you could not add a set if no metadata was configured.
## 1.2.0: ## 1.2.0:
> **Warning** > **Warning**

View File

@ -3,7 +3,7 @@ from typing import List, overload, Self, Type, TypeVar
from flask import url_for from flask import url_for
from .exceptions import NotFoundException from .exceptions import ErrorException, NotFoundException
from .fields import BrickRecordFields from .fields import BrickRecordFields
from .record_list import BrickRecordList from .record_list import BrickRecordList
from .set_owner import BrickSetOwner from .set_owner import BrickSetOwner
@ -113,12 +113,17 @@ class BrickMetadataList(BrickRecordList[T]):
# Grab a specific status # Grab a specific status
@classmethod @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() new = cls.new()
if allow_none and id == '': if allow_none and (id == '' or id is None):
return new.model() 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: if id not in new.mapping:
raise NotFoundException( raise NotFoundException(
'{kind} with ID {id} was not found in the database'.format( '{kind} with ID {id} was not found in the database'.format(

View File

@ -1,4 +1,4 @@
from typing import Final from typing import Final
__version__: Final[str] = '1.2.0' __version__: Final[str] = '1.2.1'
__database_version__: Final[int] = 15 __database_version__: Final[int] = 15

View File

@ -84,6 +84,7 @@ def admin() -> str:
open_image = request.args.get('open_image', None) open_image = request.args.get('open_image', None)
open_instructions = request.args.get('open_instructions', None) open_instructions = request.args.get('open_instructions', None)
open_logout = request.args.get('open_logout', 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_owner = request.args.get('open_owner', None)
open_purchase_location = request.args.get('open_purchase_location', None) open_purchase_location = request.args.get('open_purchase_location', None)
open_retired = request.args.get('open_retired', 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_theme = request.args.get('open_theme', None)
open_metadata = ( open_metadata = (
open_metadata or
open_owner or open_owner or
open_purchase_location or open_purchase_location or
open_status or open_status or

View File

@ -2,7 +2,7 @@ services:
bricktracker: bricktracker:
container_name: BrickTracker container_name: BrickTracker
restart: unless-stopped restart: unless-stopped
image: gitea.baerentsen.space/frederikbaerentsen/bricktracker:1.2.0 image: gitea.baerentsen.space/frederikbaerentsen/bricktracker:1.2.1
ports: ports:
- "3333:3333" - "3333:3333"
volumes: volumes:

View File

@ -2,7 +2,7 @@ services:
bricktracker: bricktracker:
container_name: BrickTracker container_name: BrickTracker
restart: unless-stopped restart: unless-stopped
image: gitea.baerentsen.space/frederikbaerentsen/bricktracker:1.2.0 image: gitea.baerentsen.space/frederikbaerentsen/bricktracker:1.2.1
ports: ports:
- "3333:3333" - "3333:3333"
volumes: volumes:

View File

@ -37,59 +37,66 @@
</div> </div>
<h6 class="border-bottom mt-2">Metadata</h6> <h6 class="border-bottom mt-2">Metadata</h6>
<div class="accordion accordion" id="metadata"> <div class="accordion accordion" id="metadata">
{% if brickset_owners | length %} {% if not (brickset_owners | length) and not (brickset_purchase_locations | length) and not (brickset_storages | length) and not (brickset_tags | length) %}
{{ accordion.header('Owners', 'owners', 'metadata', icon='user-line') }} <div class="alert alert-warning" role="alert">
<div id="add-owners"> You have no metadata configured.
{% for owner in brickset_owners %} You can add entries in the <a href="{{ url_for('admin.admin', open_metadata=true) }}" class="btn btn-warning" role="button"><i class="ri-profile-line"></i> Set metadata management</a> section of the Admin panel.
{% with id=owner.as_dataset() %}
<div class="form-check">
<input class="form-check-input" type="checkbox" value="{{ owner.fields.id }}" id="{{ id }}" autocomplete="off">
<label class="form-check-label" for="{{ id }}">{{ owner.fields.name }}</label>
</div>
{% endwith %}
{% endfor %}
</div> </div>
{{ accordion.footer() }} {% else %}
{% endif %} {% if brickset_owners | length %}
{% if brickset_purchase_locations | length %} {{ accordion.header('Owners', 'owners', 'metadata', icon='user-line') }}
{{ accordion.header('Purchase location', 'purchase-location', 'metadata', icon='building-line') }} <div id="add-owners">
<label class="visually-hidden" for="add-purchase-location">{{ name }}</label> {% for owner in brickset_owners %}
<div class="input-group"> {% with id=owner.as_dataset() %}
<select id="add-purchase-location" class="form-select" autocomplete="off"> <div class="form-check">
<option value="" selected><i>None</i></option> <input class="form-check-input" type="checkbox" value="{{ owner.fields.id }}" id="{{ id }}" autocomplete="off">
{% for purchase_location in brickset_purchase_locations %} <label class="form-check-label" for="{{ id }}">{{ owner.fields.name }}</label>
<option value="{{ purchase_location.fields.id }}">{{ purchase_location.fields.name }}</option> </div>
{% endfor %} {% endwith %}
</select> {% endfor %}
</div> </div>
{{ accordion.footer() }} {{ accordion.footer() }}
{% endif %} {% endif %}
{% if brickset_storages | length %} {% if brickset_purchase_locations | length %}
{{ accordion.header('Storage', 'storage', 'metadata', icon='archive-2-line') }} {{ accordion.header('Purchase location', 'purchase-location', 'metadata', icon='building-line') }}
<label class="visually-hidden" for="add-storage">{{ name }}</label> <label class="visually-hidden" for="add-purchase-location">{{ name }}</label>
<div class="input-group"> <div class="input-group">
<select id="add-storage" class="form-select" autocomplete="off"> <select id="add-purchase-location" class="form-select" autocomplete="off">
<option value="" selected><i>None</i></option> <option value="" selected><i>None</i></option>
{% for storage in brickset_storages %} {% for purchase_location in brickset_purchase_locations %}
<option value="{{ storage.fields.id }}">{{ storage.fields.name }}</option> <option value="{{ purchase_location.fields.id }}">{{ purchase_location.fields.name }}</option>
{% endfor %} {% endfor %}
</select> </select>
</div> </div>
{{ accordion.footer() }} {{ accordion.footer() }}
{% endif %} {% endif %}
{% if brickset_tags | length %} {% if brickset_storages | length %}
{{ accordion.header('Tags', 'tags', 'metadata', icon='price-tag-2-line') }} {{ accordion.header('Storage', 'storage', 'metadata', icon='archive-2-line') }}
<div id="add-tags"> <label class="visually-hidden" for="add-storage">{{ name }}</label>
{% for tag in brickset_tags %} <div class="input-group">
{% with id=tag.as_dataset() %} <select id="add-storage" class="form-select" autocomplete="off">
<div class="form-check"> <option value="" selected><i>None</i></option>
<input class="form-check-input" type="checkbox" value="{{ tag.fields.id }}" id="{{ id }}" autocomplete="off"> {% for storage in brickset_storages %}
<label class="form-check-label" for="{{ id }}">{{ tag.fields.name }}</label> <option value="{{ storage.fields.id }}">{{ storage.fields.name }}</option>
</div> {% endfor %}
{% endwith %} </select>
{% endfor %} </div>
</div> {{ accordion.footer() }}
{{ accordion.footer() }} {% endif %}
{% if brickset_tags | length %}
{{ accordion.header('Tags', 'tags', 'metadata', icon='price-tag-2-line') }}
<div id="add-tags">
{% for tag in brickset_tags %}
{% with id=tag.as_dataset() %}
<div class="form-check">
<input class="form-check-input" type="checkbox" value="{{ tag.fields.id }}" id="{{ id }}" autocomplete="off">
<label class="form-check-label" for="{{ id }}">{{ tag.fields.name }}</label>
</div>
{% endwith %}
{% endfor %}
</div>
{{ accordion.footer() }}
{% endif %}
{% endif %} {% endif %}
</div> </div>
<hr> <hr>