43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
import logging
|
|
from typing import Self
|
|
|
|
from flask import current_app
|
|
|
|
from .metadata_list import BrickMetadataList
|
|
from .set_purchase_location import BrickSetPurchaseLocation
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
# Lego sets purchase location list
|
|
class BrickSetPurchaseLocationList(
|
|
BrickMetadataList[BrickSetPurchaseLocation]
|
|
):
|
|
kind: str = 'set purchase locations'
|
|
|
|
# Queries
|
|
select_query = 'set/metadata/purchase_location/list'
|
|
all_query = 'set/metadata/purchase_location/all'
|
|
|
|
# Set value endpoint
|
|
set_value_endpoint: str = 'set.update_purchase_location'
|
|
|
|
# Load all purchase locations
|
|
@classmethod
|
|
def all(cls, /) -> Self:
|
|
new = cls.new()
|
|
new.override()
|
|
|
|
for record in new.select(
|
|
override_query=cls.all_query,
|
|
order=current_app.config['PURCHASE_LOCATION_DEFAULT_ORDER']
|
|
):
|
|
new.records.append(new.model(record=record))
|
|
|
|
return new
|
|
|
|
# Instantiate the list with the proper class
|
|
@classmethod
|
|
def new(cls, /, *, force: bool = False) -> Self:
|
|
return cls(BrickSetPurchaseLocation, force=force)
|