Adding filters and controls for scopes

This commit is contained in:
Ian Roddis committed 2026-07-27 14:59:03 -03:00
1 parent 3febc15a8f
commit 2587ccbceb
6 files changed
+292 -94

No files matched your search

+25 -2
View File
@@ -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}
)