2025-02-03 22:20:43 +01:00
|
|
|
from typing import Any, Self
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
from flask import current_app
|
|
|
|
|
|
|
|
from .record_list import BrickRecordList
|
2025-01-31 16:34:52 +01:00
|
|
|
from .set_owner_list import BrickSetOwnerList
|
2025-01-30 15:03:16 +01:00
|
|
|
from .set_status_list import BrickSetStatusList
|
2025-01-31 18:08:53 +01:00
|
|
|
from .set_tag_list import BrickSetTagList
|
2025-01-17 11:03:00 +01:00
|
|
|
from .set import BrickSet
|
|
|
|
|
|
|
|
|
|
|
|
# All the sets from the database
|
|
|
|
class BrickSetList(BrickRecordList[BrickSet]):
|
|
|
|
themes: list[str]
|
2025-01-18 23:13:36 +01:00
|
|
|
order: str
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
# Queries
|
2025-01-31 20:46:36 +01:00
|
|
|
damaged_minifigure_query: str = 'set/list/damaged_minifigure'
|
|
|
|
damaged_part_query: str = 'set/list/damaged_part'
|
2025-01-17 11:03:00 +01:00
|
|
|
generic_query: str = 'set/list/generic'
|
2025-01-24 10:36:24 +01:00
|
|
|
light_query: str = 'set/list/light'
|
2025-01-17 11:03:00 +01:00
|
|
|
missing_minifigure_query: str = 'set/list/missing_minifigure'
|
|
|
|
missing_part_query: str = 'set/list/missing_part'
|
|
|
|
select_query: str = 'set/list/all'
|
|
|
|
using_minifigure_query: str = 'set/list/using_minifigure'
|
|
|
|
using_part_query: str = 'set/list/using_part'
|
|
|
|
|
|
|
|
def __init__(self, /):
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
# Placeholders
|
|
|
|
self.themes = []
|
|
|
|
|
2025-01-18 23:13:36 +01:00
|
|
|
# Store the order for this list
|
2025-01-20 15:20:07 +01:00
|
|
|
self.order = current_app.config['SETS_DEFAULT_ORDER']
|
2025-01-18 23:13:36 +01:00
|
|
|
|
2025-01-17 11:03:00 +01:00
|
|
|
# All the sets
|
|
|
|
def all(self, /) -> Self:
|
|
|
|
# Load the sets from the database
|
2025-02-03 22:20:43 +01:00
|
|
|
self.list(do_theme=True)
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
return self
|
|
|
|
|
2025-01-31 20:46:36 +01:00
|
|
|
# Sets with a minifigure part damaged
|
|
|
|
def damaged_minifigure(self, figure: str, /) -> Self:
|
|
|
|
# Save the parameters to the fields
|
|
|
|
self.fields.figure = figure
|
|
|
|
|
|
|
|
# Load the sets from the database
|
2025-02-03 22:20:43 +01:00
|
|
|
self.list(override_query=self.damaged_minifigure_query)
|
2025-01-31 20:46:36 +01:00
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
# Sets with a part damaged
|
|
|
|
def damaged_part(self, part: str, color: int, /) -> Self:
|
|
|
|
# Save the parameters to the fields
|
|
|
|
self.fields.part = part
|
|
|
|
self.fields.color = color
|
|
|
|
|
|
|
|
# Load the sets from the database
|
2025-02-03 22:20:43 +01:00
|
|
|
self.list(override_query=self.damaged_part_query)
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
# Last added sets
|
2025-01-22 16:36:35 +01:00
|
|
|
def last(self, /, *, limit: int = 6) -> Self:
|
2025-01-17 11:03:00 +01:00
|
|
|
# Randomize
|
2025-01-20 15:20:07 +01:00
|
|
|
if current_app.config['RANDOM']:
|
2025-01-17 11:03:00 +01:00
|
|
|
order = 'RANDOM()'
|
|
|
|
else:
|
2025-01-24 10:36:24 +01:00
|
|
|
order = '"bricktracker_sets"."rowid" DESC'
|
2025-01-17 11:03:00 +01:00
|
|
|
|
2025-02-03 22:20:43 +01:00
|
|
|
self.list(order=order, limit=limit)
|
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
# Base set list
|
|
|
|
def list(
|
|
|
|
self,
|
|
|
|
/,
|
|
|
|
*,
|
|
|
|
override_query: str | None = None,
|
|
|
|
order: str | None = None,
|
|
|
|
limit: int | None = None,
|
|
|
|
do_theme: bool = False,
|
|
|
|
**context: Any,
|
|
|
|
) -> None:
|
|
|
|
themes = set()
|
|
|
|
|
|
|
|
if order is None:
|
|
|
|
order = self.order
|
|
|
|
|
|
|
|
# Load the sets from the database
|
|
|
|
for record in super().select(
|
|
|
|
override_query=override_query,
|
2025-01-24 10:36:24 +01:00
|
|
|
order=order,
|
|
|
|
limit=limit,
|
2025-02-03 16:46:45 +01:00
|
|
|
owners=BrickSetOwnerList.as_columns(),
|
|
|
|
statuses=BrickSetStatusList.as_columns(),
|
|
|
|
tags=BrickSetTagList.as_columns(),
|
2025-01-24 10:36:24 +01:00
|
|
|
):
|
2025-01-17 11:03:00 +01:00
|
|
|
brickset = BrickSet(record=record)
|
|
|
|
|
|
|
|
self.records.append(brickset)
|
2025-02-03 22:20:43 +01:00
|
|
|
if do_theme:
|
|
|
|
themes.add(brickset.theme.name)
|
2025-01-17 11:03:00 +01:00
|
|
|
|
2025-02-03 22:20:43 +01:00
|
|
|
# Convert the set into a list and sort it
|
|
|
|
if do_theme:
|
|
|
|
self.themes = list(themes)
|
|
|
|
self.themes.sort()
|
2025-01-17 11:03:00 +01:00
|
|
|
|
2025-01-31 20:46:36 +01:00
|
|
|
# Sets missing a minifigure part
|
2025-01-27 18:39:35 +01:00
|
|
|
def missing_minifigure(self, figure: str, /) -> Self:
|
2025-01-17 11:03:00 +01:00
|
|
|
# Save the parameters to the fields
|
2025-01-27 18:39:35 +01:00
|
|
|
self.fields.figure = figure
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
# Load the sets from the database
|
2025-02-03 22:20:43 +01:00
|
|
|
self.list(override_query=self.missing_minifigure_query)
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
# Sets missing a part
|
2025-01-31 16:37:42 +01:00
|
|
|
def missing_part(self, part: str, color: int, /) -> Self:
|
2025-01-17 11:03:00 +01:00
|
|
|
# Save the parameters to the fields
|
2025-01-28 19:18:51 +01:00
|
|
|
self.fields.part = part
|
|
|
|
self.fields.color = color
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
# Load the sets from the database
|
2025-02-03 22:20:43 +01:00
|
|
|
self.list(override_query=self.missing_part_query)
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
# Sets using a minifigure
|
2025-01-27 18:39:35 +01:00
|
|
|
def using_minifigure(self, figure: str, /) -> Self:
|
2025-01-17 11:03:00 +01:00
|
|
|
# Save the parameters to the fields
|
2025-01-27 18:39:35 +01:00
|
|
|
self.fields.figure = figure
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
# Load the sets from the database
|
2025-02-03 22:20:43 +01:00
|
|
|
self.list(override_query=self.using_minifigure_query)
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
# Sets using a part
|
2025-01-31 16:37:42 +01:00
|
|
|
def using_part(self, part: str, color: int, /) -> Self:
|
2025-01-17 11:03:00 +01:00
|
|
|
# Save the parameters to the fields
|
2025-01-28 19:18:51 +01:00
|
|
|
self.fields.part = part
|
|
|
|
self.fields.color = color
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
# Load the sets from the database
|
2025-02-03 22:20:43 +01:00
|
|
|
self.list(override_query=self.using_part_query)
|
2025-01-17 11:03:00 +01:00
|
|
|
|
|
|
|
return self
|