Some checks failed
Test Suite / pytest-backend (push) Failing after 2s
Test Suite / k6 /api/health Baseline (push) Has been skipped
Test Suite / playwright-smoke (push) Has been skipped
Test Suite / lint-backend (push) Successful in 3s
Test Suite / compose-smoke (push) Has been skipped
Deploy Development / deploy (push) Failing after 50s
Method-Profiles-API und Auswahl beim Anlegen/Profil; Steuerungs-Meta in Listen und Plan; Projekt-Archetyp-Spiegel, Next-Action-Links und Umlaut-Fix fuer testbare Guidance. Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
1.7 KiB
Python
52 lines
1.7 KiB
Python
"""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
|
|
from steering.methods.registry import get_method
|
|
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,
|
|
)
|
|
method = get_method(row["method_key"])
|
|
metadata = row.get("lifecycle_metadata") or {}
|
|
if isinstance(metadata, str):
|
|
metadata = {}
|
|
method_profile_key = metadata.get("method_profile_key")
|
|
method_profile_label = None
|
|
if method_profile_key:
|
|
from method_profiles.registry import get_method_profile
|
|
|
|
profile = get_method_profile(method_profile_key)
|
|
if profile:
|
|
method_profile_label = profile.get("label")
|
|
return {
|
|
**row,
|
|
"lifecycle_label": lifecycle_label(row["lifecycle_state"]),
|
|
"method_label": method.label if method else row["method_key"],
|
|
"method_profile_key": method_profile_key,
|
|
"method_profile_label": method_profile_label,
|
|
}
|
|
|
|
|
|
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
|