2026-07-05 17:09:20 +02:00
|
|
|
"""SteeringContext read helpers — AP1.0."""
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
|
|
from typing import Any, Optional
|
|
|
|
|
|
|
|
|
|
from services import steering_context as sc_service
|
|
|
|
|
from steering.lifecycle.states import lifecycle_label
|
2026-07-05 17:24:17 +02:00
|
|
|
from steering.methods.registry import get_method
|
2026-07-05 17:09:20 +02:00
|
|
|
from tenant_context import TenantContext
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_steering_context_dto(
|
|
|
|
|
ctx: TenantContext, *, initiative_id: str
|
|
|
|
|
) -> Optional[dict[str, Any]]:
|
|
|
|
|
row = sc_service.get_steering_context(
|
|
|
|
|
tenant_id=ctx.tenant_id, initiative_id=initiative_id
|
|
|
|
|
)
|
|
|
|
|
if not row:
|
|
|
|
|
row = sc_service.ensure_steering_context(
|
|
|
|
|
tenant_id=ctx.tenant_id,
|
|
|
|
|
initiative_id=initiative_id,
|
|
|
|
|
)
|
2026-07-05 17:24:17 +02:00
|
|
|
method = get_method(row["method_key"])
|
2026-07-05 17:09:20 +02:00
|
|
|
return {
|
|
|
|
|
**row,
|
|
|
|
|
"lifecycle_label": lifecycle_label(row["lifecycle_state"]),
|
2026-07-05 17:24:17 +02:00
|
|
|
"method_label": method.label if method else row["method_key"],
|
2026-07-05 17:09:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_or_create_for_initiative(
|
|
|
|
|
ctx: TenantContext, *, initiative_id: str
|
|
|
|
|
) -> dict[str, Any]:
|
|
|
|
|
dto = get_steering_context_dto(ctx, initiative_id=initiative_id)
|
|
|
|
|
if not dto:
|
|
|
|
|
raise ValueError("SteeringContext nicht verfügbar")
|
|
|
|
|
return dto
|