Merge branch 'r2-web'
# Conflicts: # app/static/roles.js # app/web/api.py # tests/test_web.py
This commit is contained in:
commit
a629eda8de
13 files changed
+548
-203
No files matched your search
+68
-2
@@ -823,13 +823,79 @@ class ExtractResult(ModelTaskResult):
|
||||
|
||||
|
||||
class ScoredRole(Role):
|
||||
"""A role as `/api/roles` serves it: with one agent's score and gate
|
||||
reason when an agent was asked for, and without otherwise."""
|
||||
"""A role as `/api/roles/{uid}` serves it: with one agent's score and
|
||||
gate reason when an agent was asked for, and without otherwise."""
|
||||
|
||||
score: float | None = None
|
||||
gated_reason: str = ""
|
||||
|
||||
|
||||
#: How many characters `RoleRow.excerpt` keeps at most: the feed row's own
|
||||
#: cap, built once here rather than by the client, so a list response never
|
||||
#: carries more of a role's text than a row draws.
|
||||
EXCERPT_LIMIT = 200
|
||||
|
||||
|
||||
def excerpt(text: str, limit: int = EXCERPT_LIMIT) -> str:
|
||||
"""`text` (a role's summary, or the opening of its description) with its
|
||||
whitespace collapsed, cut to `limit` characters at a word boundary with
|
||||
an ellipsis. What `Store.roles_page` builds `RoleRow.excerpt` with, off a
|
||||
`SUBSTR` of the source column rather than the whole of it, so the feed's
|
||||
list never carries what only the reader needs."""
|
||||
collapsed = " ".join((text or "").split())
|
||||
if len(collapsed) <= limit:
|
||||
return collapsed
|
||||
cut = collapsed[:limit]
|
||||
space = cut.rfind(" ")
|
||||
trimmed = cut[:space] if space > limit * 0.6 else cut
|
||||
return trimmed.rstrip(" ,.;:" + chr(0x2013) + "-") + "…"
|
||||
|
||||
|
||||
class RoleRow(Model):
|
||||
"""One row of the feed: what `GET /api/roles` serves per role, the
|
||||
fields a row draws and nothing else — never `description`, `feed_text`,
|
||||
`raw` or `article_text`, the four columns docs/decisions.md measures at
|
||||
about 5.5 KB a role between them. The reader fetches the rest by uid when
|
||||
it opens a role (`GET /api/roles/{uid}`, the full `Role`).
|
||||
|
||||
`excerpt` is built on the server (see `excerpt`, above): the summary when
|
||||
there is one, else the description's opening, cut to `EXCERPT_LIMIT`
|
||||
characters. The pay fields are what the row's badge reads: the three
|
||||
normalised columns, the line the board stated, and `salary_state`,
|
||||
derived as on `Role`. `original_url` is one short string, kept so the
|
||||
`o` key opens a selected row's posting without opening the reader."""
|
||||
|
||||
uid: str
|
||||
company_key: str = ""
|
||||
company: str = ""
|
||||
title: str = ""
|
||||
place: str = ""
|
||||
country: str = ""
|
||||
remote: Remote = ""
|
||||
function: str = ""
|
||||
salary_min: int | None = None
|
||||
salary_max: int | None = None
|
||||
currency: str = ""
|
||||
salary_text: str = ""
|
||||
original_url: str = ""
|
||||
posted_at: str = ""
|
||||
score: float | None = None
|
||||
gated_reason: str = ""
|
||||
vote: Literal[-1, 0, 1] | None = None
|
||||
voted_at: str | None = None
|
||||
read_at: str | None = None
|
||||
tags: list[str] = []
|
||||
excerpt: str = ""
|
||||
|
||||
@computed_field # type: ignore[prop-decorator]
|
||||
@property
|
||||
def salary_state(self) -> str:
|
||||
"""As `Role.salary_state`: 'normalised', 'stated' or ''."""
|
||||
if self.salary_min is not None or self.salary_max is not None:
|
||||
return "normalised"
|
||||
return "stated" if self.salary_text else ""
|
||||
|
||||
|
||||
class Company(Model):
|
||||
"""A row of `companies`, with `affinity` as the agent it was read for
|
||||
has it (see `agent_companies`); 0 when no agent was asked for."""
|
||||
|
||||
Reference in new issue
Block a user