feat: update status codes and navigation structure in calculations and reports routes

This commit is contained in:
2025-11-13 17:14:17 +01:00
parent 522b1e4105
commit ed8e05147c
8 changed files with 462 additions and 36 deletions

View File

@@ -1281,7 +1281,7 @@ def opex_form(
project=project,
scenario=scenario,
)
return templates.TemplateResponse(_opex_TEMPLATE, context)
return templates.TemplateResponse(request, _opex_TEMPLATE, context)
@router.post(
@@ -1310,7 +1310,7 @@ async def opex_submit(
except ValidationError as exc:
if wants_json:
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
content={"errors": exc.errors()},
)
@@ -1329,14 +1329,15 @@ async def opex_submit(
component_errors=component_errors,
)
return templates.TemplateResponse(
request,
_opex_TEMPLATE,
context,
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
)
except OpexValidationError as exc:
if wants_json:
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
content={
"errors": list(exc.field_errors or []),
"message": exc.message,
@@ -1355,9 +1356,10 @@ async def opex_submit(
errors=errors,
)
return templates.TemplateResponse(
request,
_opex_TEMPLATE,
context,
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
)
project, scenario = _load_project_and_scenario(
@@ -1390,6 +1392,7 @@ async def opex_submit(
notices.append("Opex calculation completed successfully.")
return templates.TemplateResponse(
request,
_opex_TEMPLATE,
context,
status_code=status.HTTP_200_OK,
@@ -1420,7 +1423,7 @@ def capex_form(
project=project,
scenario=scenario,
)
return templates.TemplateResponse("scenarios/capex.html", context)
return templates.TemplateResponse(request, "scenarios/capex.html", context)
@router.post(
@@ -1447,7 +1450,7 @@ async def capex_submit(
except ValidationError as exc:
if wants_json:
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
content={"errors": exc.errors()},
)
@@ -1466,14 +1469,15 @@ async def capex_submit(
component_errors=component_errors,
)
return templates.TemplateResponse(
request,
"scenarios/capex.html",
context,
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
)
except CapexValidationError as exc:
if wants_json:
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
content={
"errors": list(exc.field_errors or []),
"message": exc.message,
@@ -1492,9 +1496,10 @@ async def capex_submit(
errors=errors,
)
return templates.TemplateResponse(
request,
"scenarios/capex.html",
context,
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
)
project, scenario = _load_project_and_scenario(
@@ -1527,6 +1532,7 @@ async def capex_submit(
notices.append("Capex calculation completed successfully.")
return templates.TemplateResponse(
request,
"scenarios/capex.html",
context,
status_code=status.HTTP_200_OK,
@@ -1569,7 +1575,11 @@ def _render_profitability_form(
metadata=metadata,
)
return templates.TemplateResponse("scenarios/profitability.html", context)
return templates.TemplateResponse(
request,
"scenarios/profitability.html",
context,
)
@router.get(
@@ -1644,7 +1654,7 @@ async def _handle_profitability_submission(
except ValidationError as exc:
if wants_json:
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
content={"errors": exc.errors()},
)
@@ -1664,14 +1674,15 @@ async def _handle_profitability_submission(
[f"{err['loc']} - {err['msg']}" for err in exc.errors()]
)
return templates.TemplateResponse(
request,
"scenarios/profitability.html",
context,
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
)
except ProfitabilityValidationError as exc:
if wants_json:
return JSONResponse(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
content={
"errors": exc.field_errors or [],
"message": exc.message,
@@ -1693,9 +1704,10 @@ async def _handle_profitability_submission(
errors = _list_from_context(context, "errors")
errors.extend(messages)
return templates.TemplateResponse(
request,
"scenarios/profitability.html",
context,
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
)
project, scenario = _load_project_and_scenario(
@@ -1729,6 +1741,7 @@ async def _handle_profitability_submission(
notices.append("Profitability calculation completed successfully.")
return templates.TemplateResponse(
request,
"scenarios/profitability.html",
context,
status_code=status.HTTP_200_OK,