What a pull reads can now be changed on a page instead of only the command line: try a search and see its first ten results before saving it, edit or remove one, follow a company's ATS board, switch any board or search on or off, and preview and apply a prune by region. Each row shows its open roles and the countries they are in. The page and `app companies`/`app searches` call the same functions in app/jobs/sources.py. Switching a target off closes its open roles, and the pull's settle closes them again if a batch in flight reopened them. Roles pulled before `country` existed are backfilled at startup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
140 lines
4.7 KiB
Python
140 lines
4.7 KiB
Python
"""The tabs: nine pages, declared once.
|
|
|
|
`TABS` is the whole navigation. `base.html` renders it, every page marks
|
|
itself active by its own `path`, and adding a tab is one entry here plus one
|
|
template.
|
|
|
|
Every page is a shell. Roles, Applications, Agents and Companies are filled
|
|
and driven by `static/roles.js` from the JSON routes in `web/api.py`, Sources
|
|
by `static/sources.js`; Jobs,
|
|
Schedules and Account are shells around the modules' own elements. What the
|
|
server renders is only what a select needs to offer, so the options cannot
|
|
drift from what the store accepts.
|
|
|
|
`FUNCTIONS` is `plugins.ats`'s, not `app`'s: the nine job functions are the
|
|
classifier's vocabulary, and this reaches `plugins/` the same way `app.cli`
|
|
does, since a plugin is app-agnostic and never reaches back into `app`. The
|
|
Jobindex areas and Adzuna countries on the Sources tab come from
|
|
`plugins.search` for the same reason.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
from dataclasses import dataclass
|
|
from pathlib import Path
|
|
|
|
from fastapi import APIRouter, Request
|
|
from fastapi.responses import HTMLResponse
|
|
from fastapi.templating import Jinja2Templates
|
|
|
|
from app.models import REMOTE, STATUSES
|
|
|
|
_ROOT = Path(__file__).resolve().parents[2]
|
|
if str(_ROOT) not in sys.path:
|
|
sys.path.insert(0, str(_ROOT))
|
|
|
|
from plugins.ats import FUNCTIONS # noqa: E402
|
|
from plugins.search import ADZUNA_COUNTRIES, JOBINDEX_AREAS # noqa: E402
|
|
|
|
TEMPLATE_DIR = Path(__file__).resolve().parent.parent / "templates"
|
|
STATIC_DIR = Path(__file__).resolve().parent.parent / "static"
|
|
|
|
|
|
@dataclass(frozen=True, slots=True)
|
|
class Tab:
|
|
path: str
|
|
label: str
|
|
template: str
|
|
|
|
|
|
#: The navigation, in order. One list; `base.html` is its only reader.
|
|
TABS: tuple[Tab, ...] = (
|
|
Tab("/", "Roles", "roles.html"),
|
|
Tab("/applications", "Applications", "applications.html"),
|
|
Tab("/agents", "Agents", "agents.html"),
|
|
Tab("/companies", "Companies", "companies.html"),
|
|
Tab("/sources", "Sources", "sources.html"),
|
|
Tab("/jobs", "Jobs", "jobs.html"),
|
|
Tab("/schedules", "Schedules", "schedules.html"),
|
|
Tab("/messages", "Messages", "messages.html"),
|
|
Tab("/account", "Account", "account.html"),
|
|
)
|
|
|
|
#: `value, label` for each select option. `FUNCTIONS` is already the value a
|
|
#: role's `function` column holds; only the label is dressed up.
|
|
FUNCTION_OPTIONS = [(f, f.replace("/", " / ").capitalize()) for f in FUNCTIONS]
|
|
REMOTE_OPTIONS = [(r, r.capitalize()) for r in REMOTE if r]
|
|
STATUS_OPTIONS = [(s, s.capitalize()) for s in STATUSES]
|
|
AREA_OPTIONS = list(JOBINDEX_AREAS.items())
|
|
COUNTRY_OPTIONS = [(c, c.upper()) for c in sorted(ADZUNA_COUNTRIES)]
|
|
|
|
|
|
def asset(path: str) -> str:
|
|
"""A static URL stamped with the file's modification time, so a changed
|
|
file is a different URL and a cached stale copy is never the answer."""
|
|
name = path.lstrip("/")
|
|
try:
|
|
stamp = int((STATIC_DIR / name).stat().st_mtime)
|
|
except OSError:
|
|
return f"/static/{name}"
|
|
return f"/static/{name}?v={stamp}"
|
|
|
|
|
|
templates = Jinja2Templates(directory=str(TEMPLATE_DIR))
|
|
templates.env.globals["TABS"] = TABS
|
|
templates.env.globals["asset"] = asset
|
|
|
|
#: Out of the OpenAPI schema: these are pages.
|
|
router = APIRouter(include_in_schema=False)
|
|
|
|
|
|
def page(request: Request, name: str, **context: object) -> HTMLResponse:
|
|
return templates.TemplateResponse(request, name, context)
|
|
|
|
|
|
@router.get("/", response_class=HTMLResponse)
|
|
def roles(request: Request) -> HTMLResponse:
|
|
return page(request, "roles.html", functions=FUNCTION_OPTIONS,
|
|
remote_options=REMOTE_OPTIONS)
|
|
|
|
|
|
@router.get("/applications", response_class=HTMLResponse)
|
|
def applications(request: Request) -> HTMLResponse:
|
|
return page(request, "applications.html", status_options=STATUS_OPTIONS)
|
|
|
|
|
|
@router.get("/agents", response_class=HTMLResponse)
|
|
def agents(request: Request) -> HTMLResponse:
|
|
return page(request, "agents.html")
|
|
|
|
|
|
@router.get("/companies", response_class=HTMLResponse)
|
|
def companies(request: Request) -> HTMLResponse:
|
|
return page(request, "companies.html")
|
|
|
|
|
|
@router.get("/sources", response_class=HTMLResponse)
|
|
def sources(request: Request) -> HTMLResponse:
|
|
return page(request, "sources.html", areas=AREA_OPTIONS, countries=COUNTRY_OPTIONS)
|
|
|
|
|
|
@router.get("/jobs", response_class=HTMLResponse)
|
|
def jobs(request: Request) -> HTMLResponse:
|
|
return page(request, "jobs.html")
|
|
|
|
|
|
@router.get("/schedules", response_class=HTMLResponse)
|
|
def schedules(request: Request) -> HTMLResponse:
|
|
return page(request, "schedules.html")
|
|
|
|
|
|
@router.get("/messages", response_class=HTMLResponse)
|
|
def messages(request: Request) -> HTMLResponse:
|
|
return page(request, "messages.html")
|
|
|
|
|
|
@router.get("/account", response_class=HTMLResponse)
|
|
def account(request: Request) -> HTMLResponse:
|
|
return page(request, "account.html")
|