Merge branch 'main' into wp1-byhand-api

# Conflicts:
#	app/models.py
#	app/storage/schema.py
#	app/storage/store.py
#	app/web/api.py
#	tests/test_storage.py
#	tests/test_web.py
This commit is contained in:
Wolf committed 2026-09-29 19:25:42 +02:00
commit 1a2689e08d
17 files changed
+565 -109

No files matched your search

+62 -21
View File
@@ -306,14 +306,14 @@ class CompanyOut(BaseModel):
search listed its roles and somebody judged it (`Store.set_affinity`):
no board, not even a detached one, and no `ats`, `careers_url`, `domain`
or `hand_reason`, which every way of following a company or listing it by
hand writes one of (`jobs.sources.known_from_search_only`). `by_hand`
marks a company on the list checked by hand: no board shown and not
`from_search`. `hand_reason` says why (`app.models.HAND_REASONS`) and
`checked_at` when a person last looked at its careers page, "" for never."""
hand writes one of (`jobs.sources.known_from_search_only`). `watch` and
`careers_opened_at` are the Watchlist's (`Company`'s), the latter also
when a person last looked at the careers page. `by_hand` marks a company
with no board shown that is not `from_search`, and `hand_reason` says why
it is read by hand (`app.models.HAND_REASONS`)."""
key: str
name: str
domain: str = ""
notes: str = ""
board: str
subscription_id: int | None = None
@@ -324,11 +324,14 @@ class CompanyOut(BaseModel):
ats_slug: str = ""
careers_url: str = ""
country: str = ""
city: str = ""
domain: str = ""
watch: int | None = None
careers_opened_at: str = ""
failing_since: str = ""
failing_reason: str = ""
from_search: bool = False
hand_reason: str = ""
checked_at: str = ""
by_hand: bool = False
@@ -357,13 +360,14 @@ def _company_outs(store: Store, agent: int | None) -> list[CompanyOut]:
sub_id, host, on, target = boards.get(c.key, (None, "", None, ""))
since, reason = failing.get(target, ("", ""))
from_search = jobs.sources.known_from_search_only(c, ever_boarded)
out.append(CompanyOut(key=c.key, name=c.name, domain=c.domain, notes=c.notes,
board=host, subscription_id=sub_id, on=on,
affinity=c.affinity, open_roles=counts.get(c.key, 0),
ats=c.ats, ats_slug=c.ats_slug, careers_url=c.careers_url,
country=c.country, failing_since=since, failing_reason=reason,
out.append(CompanyOut(key=c.key, name=c.name, notes=c.notes, board=host,
subscription_id=sub_id, on=on, affinity=c.affinity,
open_roles=counts.get(c.key, 0), ats=c.ats,
ats_slug=c.ats_slug, careers_url=c.careers_url,
country=c.country, city=c.city, domain=c.domain,
watch=c.watch, careers_opened_at=c.careers_opened_at,
failing_since=since, failing_reason=reason,
from_search=from_search, hand_reason=c.hand_reason,
checked_at=c.checked_at,
by_hand=c.key not in boards and not from_search))
return out
@@ -428,15 +432,6 @@ def edit_company(key: str, body: CompanyPatch, store: StoreDep) -> CompanyOut:
return _one_company(store, key)
@router.post("/companies/{key}/checked")
def company_checked(key: str, store: StoreDep) -> CompanyOut:
"""A person has just looked at the company's careers page."""
if store.company(key) is None:
raise HTTPException(404, f"no such company: {key}")
store.update_company(key, checked_at=store.now())
return _one_company(store, key)
@router.delete("/companies/{key}", status_code=204)
def remove_company(key: str, store: StoreDep) -> Response:
"""Delete a company and every agent's stance on it. 409 for one with a
@@ -549,6 +544,52 @@ def set_affinity(key: str, body: AffinityBody, store: StoreDep,
return AffinityOut(**company.model_dump(), score_job=job.id if job else None)
class WatchBody(BaseModel):
#: True on the Watchlist's list, False not on it, None clears the rating.
watch: bool | None
@router.post("/companies/{key}/watch")
def set_watch(key: str, body: WatchBody, store: StoreDep) -> Company:
"""Rate a company for the Watchlist: 1 worth checking by hand, 0 not,
null back to unrated. Global, and apart from affinity. 404 for an
unknown key."""
watch = None if body.watch is None else int(body.watch)
try:
return store.update_company(key, watch=watch)
except KeyError:
raise HTTPException(404, f"no such company: {key}") from None
class CareersBody(BaseModel):
careers_url: str
@router.post("/companies/{key}/careers")
def set_careers_url(key: str, body: CareersBody, store: StoreDep) -> Company:
"""Set or correct where a company's careers page is; "" clears it. 422
for anything but an http(s) URL (`jobs.sources.check_careers_url`, the
rule the by-hand edit shares), 404 for an unknown key."""
try:
url = jobs.sources.check_careers_url(body.careers_url)
except ValueError as exc:
raise HTTPException(422, str(exc)) from exc
try:
return store.update_company(key, careers_url=url)
except KeyError:
raise HTTPException(404, f"no such company: {key}") from None
@router.post("/companies/{key}/opened")
def mark_careers_opened(key: str, store: StoreDep) -> Company:
"""Stamp that the company's careers page was just opened from the
Watchlist. 404 for an unknown key."""
try:
return store.update_company(key, careers_opened_at=store.now())
except KeyError:
raise HTTPException(404, f"no such company: {key}") from None
# ----------------------------------------------------------------- sources
class SourceOut(BaseModel):
+8 -2
View File
@@ -1,6 +1,6 @@
"""The pages: two tabs, a cog, and three settings pages behind it.
"""The pages: three tabs, a cog, and three settings pages behind it.
`TABS` is the top bar, Roles and Applications, and `SETTINGS` is the rail
`TABS` is the top bar, Roles, Applications and Watchlist, and `SETTINGS` is the rail
beside every page under the cog at `/settings/<name>`: Search agents,
Sources, Account. `base.html` renders the first, `settings/_rail.html` the
second, every page marks itself active by its own `path`, and adding one is
@@ -68,6 +68,7 @@ class Tab:
TABS: tuple[Tab, ...] = (
Tab("/", "Roles", "roles.html"),
Tab("/applications", "Applications", "applications.html"),
Tab("/watchlist", "Watchlist", "watchlist.html"),
)
#: The pages under the cog, in order; `settings/_rail.html` renders them.
@@ -155,6 +156,11 @@ def applications(request: Request) -> HTMLResponse:
return page(request, "applications.html", status_options=STATUS_OPTIONS)
@router.get("/watchlist", response_class=HTMLResponse)
def watchlist(request: Request) -> HTMLResponse:
return page(request, "watchlist.html")
@router.get("/settings", response_class=RedirectResponse)
def settings() -> RedirectResponse:
return RedirectResponse(SETTINGS[0].path, status_code=302)