From 5786c8d83c02c29f12620937258bca373a3e2ecf Mon Sep 17 00:00:00 2001 From: jbirddog <100367399+jbirddog@users.noreply.github.com> Date: Fri, 18 Nov 2022 07:40:36 -0500 Subject: [PATCH] Support reporting on task data (#47) --- .../routes/process_api_blueprint.py | 18 ++++++------------ .../services/process_instance_service.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py index a5b4c0aa3..b3d5ec020 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/process_api_blueprint.py @@ -811,18 +811,12 @@ def process_instance_list( ProcessInstanceModel.start_in_seconds.desc(), ProcessInstanceModel.id.desc() # type: ignore ).paginate(page=page, per_page=per_page, error_out=False) - # TODO need to look into test failures when the results from result_dict is - # used instead of the process instances - - # substitution_variables = request.args.to_dict() - # result_dict = process_instance_report.generate_report( - # process_instances.items, substitution_variables - # ) - - # results = result_dict["results"] - # report_metadata = result_dict["report_metadata"] - - results = process_instances.items + results = list( + map( + ProcessInstanceService.serialize_flat_with_task_data, + process_instances.items, + ) + ) report_metadata = process_instance_report.report_metadata response_json = { diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py index aac9b1760..244e6fb2d 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_service.py @@ -315,3 +315,22 @@ class ProcessInstanceService: ) return task + + @staticmethod + def serialize_flat_with_task_data( + process_instance: ProcessInstanceModel, + ) -> dict[str, Any]: + """serialize_flat_with_task_data.""" + results = {} + try: + original_status = process_instance.status + processor = ProcessInstanceProcessor(process_instance) + process_instance.data = processor.get_current_data() + results = process_instance.serialized_flat + # this process seems to mutate the status of the process_instance which + # can result in different results than expected from process_instance_list, + # so set the status back to the expected value + results["status"] = original_status + except ApiError: + results = process_instance.serialized + return results