41 lines
1.7 KiB
Python
41 lines
1.7 KiB
Python
"""
|
|
Formatting utilities for NimbusFlow CLI.
|
|
"""
|
|
|
|
from typing import Optional
|
|
from datetime import datetime
|
|
from backend.models.enums import ScheduleStatus
|
|
|
|
|
|
def format_member_row(member, classification_name: Optional[str] = None) -> str:
|
|
"""Format a member for table display."""
|
|
active = "✓" if member.IsActive else "✗"
|
|
classification = classification_name or "N/A"
|
|
return f"{member.MemberId:3d} | {member.FirstName:<12} | {member.LastName:<15} | {classification:<12} | {active:^6} | {member.Email or 'N/A'}"
|
|
|
|
|
|
def format_schedule_row(schedule, member_name: str = "", service_info: str = "") -> str:
|
|
"""Format a schedule for table display."""
|
|
status_symbols = {
|
|
ScheduleStatus.PENDING: "⏳",
|
|
ScheduleStatus.ACCEPTED: "✅",
|
|
ScheduleStatus.DECLINED: "❌"
|
|
}
|
|
status_symbol = status_symbols.get(ScheduleStatus.from_raw(schedule.Status), "❓")
|
|
|
|
# Handle ScheduledAt - could be datetime object or string from DB
|
|
if schedule.ScheduledAt:
|
|
if isinstance(schedule.ScheduledAt, str):
|
|
# If it's a string, try to parse and format it, or use as-is
|
|
try:
|
|
dt_obj = datetime.fromisoformat(schedule.ScheduledAt.replace('Z', '+00:00'))
|
|
scheduled_date = dt_obj.strftime("%Y-%m-%d %H:%M")
|
|
except (ValueError, AttributeError):
|
|
scheduled_date = str(schedule.ScheduledAt)
|
|
else:
|
|
# If it's already a datetime object
|
|
scheduled_date = schedule.ScheduledAt.strftime("%Y-%m-%d %H:%M")
|
|
else:
|
|
scheduled_date = "N/A"
|
|
|
|
return f"{schedule.ScheduleId:3d} | {status_symbol} {schedule.Status:<8} | {member_name:<20} | {service_info:<15} | {scheduled_date}" |