Adding filters and controls for scopes
This commit is contained in:
1 parent
3febc15a8f
commit
2587ccbceb
6 files changed
+292
-94
No files matched your search
@@ -19,9 +19,22 @@ SCOPE_TYPE_NAME = "Scope"
|
||||
_LABEL_RANK = {FitLabel.EXACT.value: 2, FitLabel.POSSIBLE.value: 1}
|
||||
|
||||
|
||||
async def build(db: AsyncSession) -> dict:
|
||||
async def build(
|
||||
db: AsyncSession,
|
||||
*,
|
||||
description: str = "",
|
||||
manufacturer_id: int | None = None,
|
||||
scope_model_id: int | None = None,
|
||||
sub_part_type_id: int | None = None,
|
||||
fits_part_type_id: int | None = None,
|
||||
) -> dict:
|
||||
"""Return the context for ``scopes.html``.
|
||||
|
||||
The scope rows are narrowed by the scope-attribute filters (``description``
|
||||
matches the scope's description; the ``*_id`` filters match exactly).
|
||||
``fits_part_type_id`` keeps only scopes that have at least one (non-``none``)
|
||||
fit for that part type.
|
||||
|
||||
Shape::
|
||||
|
||||
{
|
||||
@@ -47,7 +60,15 @@ async def build(db: AsyncSession) -> dict:
|
||||
if scope_type is None:
|
||||
return {"column_types": column_types, "rows": []}
|
||||
|
||||
scopes = await augmented_part_crud.list_by_part_type(db, scope_type.id)
|
||||
scopes = await augmented_part_crud.list_filtered(
|
||||
db,
|
||||
description=description,
|
||||
manufacturer_id=manufacturer_id,
|
||||
scope_model_id=scope_model_id,
|
||||
sub_part_type_id=sub_part_type_id,
|
||||
part_type_id=scope_type.id,
|
||||
limit=1000,
|
||||
)
|
||||
scope_ids = {s.id for s in scopes}
|
||||
if not scope_ids:
|
||||
return {"column_types": column_types, "rows": []}
|
||||
@@ -97,6 +118,8 @@ async def build(db: AsyncSession) -> dict:
|
||||
)
|
||||
for type_id, entries in cell_map[scope.id].items()
|
||||
}
|
||||
if fits_part_type_id is not None and fits_part_type_id not in cells:
|
||||
continue # scope has no fit for the required accessory type
|
||||
rows.append(
|
||||
{"scope": scope, "info": infos.get(scope.id), "cells": cells}
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user