Filter seniority by a range of rungs and a track: level_from, level_to, track; From, To and Track in the rail (WP B)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus 5.5 committed 2026-09-30 13:03:31 +02:00
1 parent ae978594b4
commit 4e390d97ca
6 files changed
+207 -71

No files matched your search

+24 -14
View File
@@ -16,8 +16,8 @@ from pydantic import BaseModel, Field
from app import jobs, places
from app.models import (
AFFINITY, LEVELS, Agent, Application, Company, FetchTerms, Gate, Limits, Prompts, Role, RoleRow,
HandReason, ScoredRole, Status, Subscription, Weights, company_key,
AFFINITY, RUNGS, TRACKS, Agent, Application, Company, FetchTerms, Gate, Limits, Prompts, Role, RoleRow,
HandReason, ScoredRole, Status, Subscription, Weights, company_key, levels_between,
)
from app.storage import Store
from app.web.deps import ConfigDep, StoreDep
@@ -78,20 +78,27 @@ def _feed_filters(
pay: Literal["", "stated", "normalised", "stated_only"] = "",
company_keys: list[str] = Query(default=[]),
tokens: list[str] = Query(default=[], alias="places"),
seniority: list[str] = Query(default=[]),
level_from: str = "",
level_to: str = "",
track: str = "",
seniority_unknown: bool = True,
pay_unknown: bool = False,
) -> dict[str, Any]:
"""The feed's filters, as `Store.roles_page`, `count_roles` and
`role_facets` take them, read from the query of `GET /api/roles` and
`GET /api/roles/facets` alike. A place token that names nothing and a
level outside `LEVELS` are a 422 sentence, not an empty feed."""
`GET /api/roles/facets` alike. A place token that names nothing, a rung
outside `RUNGS` and a track outside `TRACKS` are a 422 sentence, not an
empty feed. The three seniority parameters become the levels between
them (`levels_between`), which is what the store filters on."""
for token in tokens:
if not places.known(token):
raise HTTPException(422, f"No place is known as {token!r}.")
for level in seniority:
if level not in LEVELS:
raise HTTPException(422, f"Seniority is one of {', '.join(LEVELS)}, not {level!r}.")
for name, rung in (("level_from", level_from), ("level_to", level_to)):
if rung and rung not in RUNGS:
raise HTTPException(422, f"{name} is one of {', '.join(RUNGS)}, not {rung!r}.")
if track and track not in TRACKS:
raise HTTPException(422, f"track is one of {', '.join(TRACKS)}, not {track!r}.")
levels = levels_between(level_from, level_to, track) if level_from or level_to or track else []
return {
"q": q or None, "company": company or None, "place": place or None,
"function": function or None, "remote": remote or None, "days": days,
@@ -99,7 +106,7 @@ def _feed_filters(
"tag_mode": tag_mode, "agent": _agent_id(store, agent),
"by_score": agent is not None and order == "score", "gated": gated,
"judged": judged or None, "pay": pay or None, "company_keys": company_keys,
"places": tokens, "seniority": seniority, "seniority_unknown": seniority_unknown,
"places": tokens, "seniority": list(levels), "seniority_unknown": seniority_unknown,
"pay_unknown": pay_unknown}
@@ -223,12 +230,15 @@ def list_roles(
as well.
`company` and `place` are substrings, kept for links from other pages.
The rail's fields are `company_keys` (repeated, exact keys),
The rail's fields are `company_keys` (repeated, exact keys) and
`places` (repeated place tokens, `app.places`: `country:DK`,
`region:skane`, `place:malmo`, matched on whole folded words) and
`seniority` (repeated levels), each several values joined by OR. A role
with no level passes the seniority filter unless `seniority_unknown` is
false. The parameters are read by `_feed_filters`.
`region:skane`, `place:malmo`, matched on whole folded words), several
values joined by OR, and the seniority range: `level_from` and
`level_to` (rungs of `RUNGS`, either or both) and `track` (`ic` or
`people`), which keep the levels between the two rungs on that track
(`levels_between`). A role with no level passes the seniority filter
unless `seniority_unknown` is false. The parameters are read by
`_feed_filters`.
A copy of another role (`Store.rebuild_dupes`) is never a row; its kept
role's `copies` says how many it stands for."""