BrickTracker/bricktracker/wish_list.py

55 lines
1.4 KiB
Python
Raw Normal View History

import logging
2025-01-17 11:03:00 +01:00
from typing import Self
from flask import current_app
from .exceptions import NotFoundException
from .parser import parse_set
from .rebrickable import Rebrickable
from .rebrickable_image import RebrickableImage
2025-01-17 11:03:00 +01:00
from .record_list import BrickRecordList
from .wish import BrickWish
logger = logging.getLogger(__name__)
2025-01-17 11:03:00 +01:00
# All the wished sets from the database
class BrickWishList(BrickRecordList[BrickWish]):
# Queries
select_query: str = 'wish/list/all'
# All the wished sets
def all(self, /) -> Self:
# Load the wished sets from the database
for record in self.select(
order=current_app.config['WISHES_DEFAULT_ORDER']
2025-01-17 11:03:00 +01:00
):
brickwish = BrickWish(record=record)
self.records.append(brickwish)
return self
# Add a set to the wishlist
@staticmethod
def add(set: str, /) -> None:
2025-01-17 11:03:00 +01:00
try:
set = parse_set(set)
BrickWish().select_specific(set)
2025-01-17 11:03:00 +01:00
except NotFoundException:
logger.debug('rebrick.lego.get_set("{set}")'.format(
set=set,
))
brickwish = Rebrickable[BrickWish](
'get_set',
set,
BrickWish,
).get()
# Insert into database
brickwish.insert()
if not current_app.config['USE_REMOTE_IMAGES']:
RebrickableImage(brickwish).download()