Reporting and TZ updates
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from typing import List, Optional
|
||||
from fastapi import APIRouter, Depends, HTTPException, status, Request
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import date
|
||||
from datetime import date, timezone
|
||||
from zoneinfo import ZoneInfo
|
||||
from app.api.deps import get_db, get_current_read_user, get_current_operator_user
|
||||
from app.crud.crud_ppr import ppr as crud_ppr
|
||||
from app.crud.crud_journal import journal as crud_journal
|
||||
@@ -19,6 +20,14 @@ from app.core.config import settings
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def format_local_datetime(dt):
|
||||
if not dt:
|
||||
return "N/A"
|
||||
if dt.tzinfo is None:
|
||||
dt = dt.replace(tzinfo=timezone.utc)
|
||||
return dt.astimezone(ZoneInfo(settings.local_timezone)).strftime("%Y-%m-%d %H:%M")
|
||||
|
||||
|
||||
@router.get("/", response_model=List[PPR])
|
||||
async def get_pprs(
|
||||
request: Request,
|
||||
@@ -94,8 +103,8 @@ async def create_public_ppr(
|
||||
template_vars={
|
||||
"name": ppr_in.captain,
|
||||
"aircraft": ppr_in.ac_reg,
|
||||
"arrival_time": ppr_in.eta.strftime("%Y-%m-%d %H:%M"),
|
||||
"departure_time": ppr_in.etd.strftime("%Y-%m-%d %H:%M") if ppr_in.etd else "N/A",
|
||||
"arrival_time": format_local_datetime(ppr_in.eta),
|
||||
"departure_time": format_local_datetime(ppr_in.etd),
|
||||
"purpose": ppr_in.notes or "N/A",
|
||||
"public_token": ppr.public_token,
|
||||
"base_url": settings.base_url
|
||||
@@ -232,8 +241,8 @@ async def update_ppr_status(
|
||||
template_vars={
|
||||
"name": ppr.captain,
|
||||
"aircraft": ppr.ac_reg,
|
||||
"arrival_time": ppr.eta.strftime("%Y-%m-%d %H:%M"),
|
||||
"departure_time": ppr.etd.strftime("%Y-%m-%d %H:%M") if ppr.etd else "N/A"
|
||||
"arrival_time": format_local_datetime(ppr.eta),
|
||||
"departure_time": format_local_datetime(ppr.etd)
|
||||
}
|
||||
)
|
||||
|
||||
@@ -316,11 +325,10 @@ async def get_ppr_for_edit(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Invalid or expired token"
|
||||
)
|
||||
# Only allow editing if not already processed
|
||||
if ppr.status in [PPRStatus.CANCELED, PPRStatus.DELETED, PPRStatus.LANDED, PPRStatus.DEPARTED]:
|
||||
if ppr.status == PPRStatus.DELETED:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail="PPR cannot be edited at this stage"
|
||||
detail="PPR is no longer available"
|
||||
)
|
||||
return ppr
|
||||
|
||||
@@ -390,8 +398,8 @@ async def cancel_ppr_public(
|
||||
template_vars={
|
||||
"name": cancelled_ppr.captain,
|
||||
"aircraft": cancelled_ppr.ac_reg,
|
||||
"arrival_time": cancelled_ppr.eta.strftime("%Y-%m-%d %H:%M"),
|
||||
"departure_time": cancelled_ppr.etd.strftime("%Y-%m-%d %H:%M") if cancelled_ppr.etd else "N/A"
|
||||
"arrival_time": format_local_datetime(cancelled_ppr.eta),
|
||||
"departure_time": format_local_datetime(cancelled_ppr.etd)
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user