TODO-app/app/validation.py

21 lines
662 B
Python

ALLOWED_STATUSES = {"not-started", "in-progress", "done"}
def normalize_status(status: str) -> str:
"""
Säkerställ att status alltid blir en av de tillåtna.
Om okänd -> default "not-started".
"""
status = (status or "").strip()
return status if status in ALLOWED_STATUSES else "not-started"
def validate_todo_fields(title: str, description: str) -> tuple[bool, list[str]]:
"""
Returnerar (ok, errors).
"""
errors = []
if not (title or "").strip():
errors.append("title_required")
if not (description or "").strip():
errors.append("description_required")
return (len(errors) == 0, errors)