feat: update status codes and navigation structure in calculations and reports routes
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -83,7 +83,7 @@ def project_summary_report(
|
||||
percentile_values = validate_percentiles(percentiles)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
|
||||
@@ -136,7 +136,7 @@ def project_scenario_comparison_report(
|
||||
unique_ids = list(dict.fromkeys(scenario_ids))
|
||||
if len(unique_ids) < 2:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail="At least two unique scenario_ids must be provided for comparison.",
|
||||
)
|
||||
if fmt.lower() != "json":
|
||||
@@ -150,7 +150,7 @@ def project_scenario_comparison_report(
|
||||
percentile_values = validate_percentiles(percentiles)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
|
||||
@@ -158,7 +158,7 @@ def project_scenario_comparison_report(
|
||||
scenarios = uow.validate_scenarios_for_comparison(unique_ids)
|
||||
except ScenarioValidationError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail={
|
||||
"code": exc.code,
|
||||
"message": exc.message,
|
||||
@@ -229,7 +229,7 @@ def scenario_distribution_report(
|
||||
percentile_values = validate_percentiles(percentiles)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
|
||||
@@ -286,7 +286,7 @@ def project_summary_page(
|
||||
percentile_values = validate_percentiles(percentiles)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
|
||||
@@ -337,7 +337,7 @@ def project_scenario_comparison_page(
|
||||
unique_ids = list(dict.fromkeys(scenario_ids))
|
||||
if len(unique_ids) < 2:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail="At least two unique scenario_ids must be provided for comparison.",
|
||||
)
|
||||
|
||||
@@ -346,7 +346,7 @@ def project_scenario_comparison_page(
|
||||
percentile_values = validate_percentiles(percentiles)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
|
||||
@@ -354,7 +354,7 @@ def project_scenario_comparison_page(
|
||||
scenarios = uow.validate_scenarios_for_comparison(unique_ids)
|
||||
except ScenarioValidationError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail={
|
||||
"code": exc.code,
|
||||
"message": exc.message,
|
||||
@@ -419,7 +419,7 @@ def scenario_distribution_page(
|
||||
percentile_values = validate_percentiles(percentiles)
|
||||
except ValueError as exc:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
|
||||
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
|
||||
detail=str(exc),
|
||||
) from exc
|
||||
|
||||
|
||||
Reference in New Issue
Block a user