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))
|
||||
|
||||
@@ -77,6 +77,8 @@ from api_server.html5_editor import (
|
||||
render_html5_symbols,
|
||||
)
|
||||
from api_server.html5_operations import (
|
||||
filter_html5_operation_jobs,
|
||||
latest_html5_import_job,
|
||||
render_html5_operation_detail,
|
||||
render_html5_operation_rows,
|
||||
render_html5_operation_summary,
|
||||
@@ -8333,33 +8335,16 @@ def _current_import_source(project_id: str) -> ImportSourceKind:
|
||||
|
||||
|
||||
def _html5_operation_jobs(project_id: str = "", status: str = "", kind: str = "") -> list[OperationJob]:
|
||||
normalized_project = project_id.strip().casefold()
|
||||
normalized_status = status.strip().casefold()
|
||||
normalized_kind = kind.strip().casefold()
|
||||
jobs = []
|
||||
for job in _operations.jobs.values():
|
||||
payload = 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
|
||||
jobs.append(job)
|
||||
return sorted(jobs, key=lambda job: job.updated_at, reverse=True)[:50]
|
||||
return filter_html5_operation_jobs(
|
||||
_operations.jobs.values(),
|
||||
project_id=project_id,
|
||||
status=status,
|
||||
kind=kind,
|
||||
)
|
||||
|
||||
|
||||
def _html5_latest_import_job(project_id: str) -> OperationJob | None:
|
||||
jobs = [
|
||||
job
|
||||
for job in _operations.jobs.values()
|
||||
if job.payload.get("project_id") == project_id and _operation_value(getattr(job, "kind", "")) == "SERVER_IMPORT"
|
||||
]
|
||||
return max(jobs, key=lambda job: job.updated_at) if jobs else None
|
||||
|
||||
|
||||
def _operation_value(value: object) -> str:
|
||||
return str(getattr(value, "value", value))
|
||||
return latest_html5_import_job(_operations.jobs.values(), project_id)
|
||||
|
||||
|
||||
def _project_summaries() -> list[ProjectSummaryResponse]:
|
||||
|
||||
Reference in New Issue
Block a user