BrickTracker/bricktracker/wish.py

44 lines
1.1 KiB
Python
Raw Normal View History

from typing import Self
2025-01-17 11:03:00 +01:00
from flask import url_for
from .exceptions import NotFoundException
from .rebrickable_set import RebrickableSet
2025-01-17 11:03:00 +01:00
from .sql import BrickSQL
# Lego brick wished set
class BrickWish(RebrickableSet):
# Flags
resolve_instructions: bool = False
2025-01-17 11:03:00 +01:00
# Queries
select_query: str = 'wish/select'
insert_query: str = 'wish/insert'
# Delete a wished set
def delete(self, /) -> None:
BrickSQL().execute_and_commit(
'wish/delete/wish',
parameters=self.sql_parameters()
)
# Select a specific part (with a set and an id)
def select_specific(self, set: str, /) -> Self:
2025-01-17 11:03:00 +01:00
# Save the parameters to the fields
self.fields.set = set
2025-01-17 11:03:00 +01:00
# Load from database
if not self.select():
2025-01-17 11:03:00 +01:00
raise NotFoundException(
'Wish for set {set} was not found in the database'.format( # noqa: E501
set=self.fields.set,
2025-01-17 11:03:00 +01:00
),
)
return self
# Deletion url
def url_for_delete(self, /) -> str:
return url_for('wish.delete', number=self.fields.set)