fix: localize admin UI and simplify employees navigation
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
from datetime import date, datetime, time
|
||||
from math import ceil
|
||||
from typing import Any
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
from sqlalchemy import Select, Text, and_, desc, func, or_, select
|
||||
from sqlalchemy.orm import Session
|
||||
@@ -30,6 +31,7 @@ def employee_display_payload(employee: Employee) -> dict[str, Any]:
|
||||
"id": employee.id,
|
||||
"full_name": employee.full_name,
|
||||
"status": employee.status,
|
||||
"status_display": _employee_status_display(employee.status),
|
||||
"canonical_url": employee.canonical_url,
|
||||
"positions": positions,
|
||||
"positions_text": "; ".join(positions),
|
||||
@@ -44,6 +46,9 @@ def employee_display_payload(employee: Employee) -> dict[str, Any]:
|
||||
"first_seen_at": employee.first_seen_at.isoformat() if employee.first_seen_at else None,
|
||||
"last_seen_at": employee.last_seen_at.isoformat() if employee.last_seen_at else None,
|
||||
"dismissed_at": employee.dismissed_at.isoformat() if employee.dismissed_at else None,
|
||||
"first_seen_display": format_admin_datetime(employee.first_seen_at),
|
||||
"last_seen_display": format_admin_datetime(employee.last_seen_at),
|
||||
"dismissed_display": format_admin_datetime(employee.dismissed_at),
|
||||
}
|
||||
|
||||
|
||||
@@ -154,8 +159,11 @@ def run_payload(run: CrawlRun | None) -> dict[str, Any] | None:
|
||||
"id": run.id,
|
||||
"source_url": run.source_url,
|
||||
"status": run.status,
|
||||
"status_display": _run_status_display(run.status),
|
||||
"started_at": run.started_at.isoformat() if run.started_at else None,
|
||||
"finished_at": run.finished_at.isoformat() if run.finished_at else None,
|
||||
"started_display": format_admin_datetime(run.started_at),
|
||||
"finished_display": format_admin_datetime(run.finished_at),
|
||||
"found_count": run.found_count,
|
||||
"parsed_count": run.parsed_count,
|
||||
"new_count": run.new_count,
|
||||
@@ -167,6 +175,31 @@ def run_payload(run: CrawlRun | None) -> dict[str, Any] | None:
|
||||
}
|
||||
|
||||
|
||||
def format_admin_datetime(value: Any) -> str:
|
||||
if not value:
|
||||
return "Не указано"
|
||||
if isinstance(value, str):
|
||||
try:
|
||||
value = datetime.fromisoformat(value.replace("Z", "+00:00"))
|
||||
except ValueError:
|
||||
return value
|
||||
if not isinstance(value, datetime):
|
||||
return str(value)
|
||||
if value.tzinfo:
|
||||
value = value.astimezone(ZoneInfo("Europe/Moscow"))
|
||||
return value.strftime("%d.%m.%Y %H:%M")
|
||||
|
||||
|
||||
def _employee_status_display(status: str | None) -> str:
|
||||
labels = {"active": "Работает", "dismissed": "Уволен"}
|
||||
return labels.get(status or "", status or "Не указано")
|
||||
|
||||
|
||||
def _run_status_display(status: str | None) -> str:
|
||||
labels = {"running": "Выполняется", "completed": "Завершен", "failed": "Ошибка"}
|
||||
return labels.get(status or "", status or "Не указано")
|
||||
|
||||
|
||||
def _count_section_items(sections: list[dict[str, Any]], section_type: str) -> int:
|
||||
total = 0
|
||||
for section in sections:
|
||||
|
||||
Reference in New Issue
Block a user