meraproject/services/user-reader/app/project_status.py
keboss-m 5c21d25d45 Initial commit: Merakomis portal, Docker stack and user-reader API.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-24 11:04:05 +03:00

45 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Статус проекта (порт themes/merakomis/project/structure/eStatus.php)."""
from __future__ import annotations
from datetime import date
from typing import Any
# tMerakomisProject_status → подпись в UI Merakomis
PROJECT_STATUS_NAMES: dict[int, str] = {
0: "Не определён",
1: "В работе",
2: "Завершён",
3: "Пауза",
}
def project_status_name(status: Any) -> str:
if status is None:
return ""
try:
return PROJECT_STATUS_NAMES.get(int(status), "")
except (TypeError, ValueError):
return ""
def _json_date(v: Any) -> Any:
if v is None:
return None
if isinstance(v, date):
return v.isoformat()
s = str(v).strip()
if not s or s.startswith("0000"):
return None
return s[:10]
def enrich_project_status_fields(item: dict[str, Any]) -> dict[str, Any]:
"""Добавляет status_name; нормализует archive_date."""
if "status" in item:
name = project_status_name(item.get("status"))
item["status_name"] = name or None
if "archive_date" in item:
item["archive_date"] = _json_date(item.get("archive_date"))
return item