Extract HTML5 operation helpers
This commit is contained in:
@@ -124,6 +124,40 @@ def render_html5_operation_detail(job: object | None) -> str:
|
||||
"""
|
||||
|
||||
|
||||
def filter_html5_operation_jobs(
|
||||
jobs: Iterable[object],
|
||||
*,
|
||||
project_id: str = "",
|
||||
status: str = "",
|
||||
kind: str = "",
|
||||
limit: int = 50,
|
||||
) -> list[object]:
|
||||
normalized_project = project_id.strip().casefold()
|
||||
normalized_status = status.strip().casefold()
|
||||
normalized_kind = kind.strip().casefold()
|
||||
filtered = []
|
||||
for job in jobs:
|
||||
payload = getattr(job, "payload", {}) or {}
|
||||
if normalized_project and str(payload.get("project_id") or "").casefold() != normalized_project:
|
||||
continue
|
||||
if normalized_status and _operation_value(getattr(job, "status", "")).casefold() != normalized_status:
|
||||
continue
|
||||
if normalized_kind and _operation_value(getattr(job, "kind", "")).casefold() != normalized_kind:
|
||||
continue
|
||||
filtered.append(job)
|
||||
return sorted(filtered, key=lambda job: getattr(job, "updated_at", ""), reverse=True)[:limit]
|
||||
|
||||
|
||||
def latest_html5_import_job(jobs: Iterable[object], project_id: str) -> object | None:
|
||||
import_jobs = [
|
||||
job
|
||||
for job in jobs
|
||||
if (getattr(job, "payload", {}) or {}).get("project_id") == project_id
|
||||
and _operation_value(getattr(job, "kind", "")) == "SERVER_IMPORT"
|
||||
]
|
||||
return max(import_jobs, key=lambda job: getattr(job, "updated_at", "")) if import_jobs else None
|
||||
|
||||
|
||||
def _operation_row(job: object) -> str:
|
||||
job_id = str(getattr(job, "job_id", ""))
|
||||
kind = str(getattr(job, "kind", ""))
|
||||
@@ -183,3 +217,7 @@ def _operation_filter_query(*, project_id: str, status: str, kind: str) -> str:
|
||||
if kind:
|
||||
params.append(f"kind={quote(kind)}")
|
||||
return f"?{'&'.join(params)}" if params else ""
|
||||
|
||||
|
||||
def _operation_value(value: object) -> str:
|
||||
return str(getattr(value, "value", value))
|
||||
|
||||
Reference in New Issue
Block a user