(20251122) Reformatted the muster roll data to return only unique combinations to reduce the load on the frontend.

This commit is contained in:
2025-11-22 11:35:03 +05:30
parent 6cbcac4545
commit 8f6736cd84
3 changed files with 49 additions and 13 deletions
+28 -2
View File
@@ -123,6 +123,16 @@ def init(blueprint_setup_state):
# ---------------------------------------------------------------------------------------------------------------------
async def close_browser() -> None:
current_app.printer("Closing failed browser session.")
current_app.cosec.quit()
current_app.printer("Cleanup attempt completed.")
# ---------------------------------------------------------------------------------------------------------------------
@muster_roll_report_bp.route("/generate", methods = ["GET"])
@set_api_version(api_version = "1.0.0")
@read_input(sanitize_headers = False, sanitize_data = False)
@@ -142,7 +152,9 @@ def init(blueprint_setup_state):
header_validator = lambda x: SimpleCosecCredentialsHeaders(**x),
data_validator = lambda x: CosecMusterRollReportRequestData(**x)
)
@handle_cancelled_request()
@handle_cancelled_request(
cleanup_coro = close_browser
)
async def muster_roll_report_generate(
inbound_headers: SimpleCosecCredentialsHeaders | dict = None,
inbound_data: CosecMusterRollReportRequestData | dict = None,
@@ -174,7 +186,21 @@ async def muster_roll_report_generate(
# If data was loaded:
if report_data is not None:
report_data = report_data.to_dict(orient = "records")
report_data = report_data.copy()
report_data = report_data[[
"User ID", "User Name", "Category Name",
"Grade Name", "Branch Name", "Department Name",
"Direct Reporting", "Level-1"
]]
unique_branches = report_data["Branch Name"].unique().tolist()
unique_depts = report_data[["Branch Name", "Department Name"]].drop_duplicates().to_dict(orient = "records")
unique_reportees = report_data[["Branch Name", "Department Name", "Direct Reporting"]].drop_duplicates().to_dict(orient = "records")
unique_combos = {
"Branch Name": unique_branches,
"Department Name": unique_depts,
"Direct Reporting": unique_reportees
}
report_data = unique_combos
success = True
# ┳┓