pyl w/ burnettk

This commit is contained in:
jasquat 2022-12-05 14:10:07 -05:00
parent 23bf85a3a0
commit 688163a1a8
4 changed files with 27 additions and 19 deletions

View File

@ -77,6 +77,7 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel):
@classmethod @classmethod
def default_order_by(cls) -> list[str]: def default_order_by(cls) -> list[str]:
"""Default_order_by."""
return ["-start_in_seconds", "-id"] return ["-start_in_seconds", "-id"]
@classmethod @classmethod

View File

@ -1,9 +1,9 @@
"""APIs for dealing with process groups, process models, and process instances.""" """APIs for dealing with process groups, process models, and process instances."""
import json import json
import random import random
import re
import string import string
import uuid import uuid
import re
from typing import Any from typing import Any
from typing import Dict from typing import Dict
from typing import Optional from typing import Optional
@ -953,10 +953,10 @@ def process_instance_list(
if column["accessor"] in stock_columns: if column["accessor"] in stock_columns:
continue continue
instance_metadata_alias = aliased(ProcessInstanceMetadataModel) instance_metadata_alias = aliased(ProcessInstanceMetadataModel)
instance_metadata_aliases[column['accessor']] = instance_metadata_alias instance_metadata_aliases[column["accessor"]] = instance_metadata_alias
filter_for_column = None filter_for_column = None
if 'filter_by' in process_instance_report.report_metadata: if "filter_by" in process_instance_report.report_metadata:
filter_for_column = next( filter_for_column = next(
( (
f f
@ -980,28 +980,34 @@ def process_instance_list(
).add_columns(func.max(instance_metadata_alias.value).label(column["accessor"])) ).add_columns(func.max(instance_metadata_alias.value).label(column["accessor"]))
order_by_query_array = [] order_by_query_array = []
order_by_array = process_instance_report.report_metadata['order_by'] order_by_array = process_instance_report.report_metadata["order_by"]
if len(order_by_array) < 1: if len(order_by_array) < 1:
order_by_array = ProcessInstanceReportModel.default_order_by() order_by_array = ProcessInstanceReportModel.default_order_by()
for order_by_option in order_by_array: for order_by_option in order_by_array:
attribute = re.sub('^-', '', order_by_option) attribute = re.sub("^-", "", order_by_option)
if attribute in stock_columns: if attribute in stock_columns:
if order_by_option.startswith('-'): if order_by_option.startswith("-"):
order_by_query_array.append(getattr(ProcessInstanceModel, attribute).desc()) order_by_query_array.append(
getattr(ProcessInstanceModel, attribute).desc()
)
else: else:
order_by_query_array.append(getattr(ProcessInstanceModel, attribute).asc()) order_by_query_array.append(
getattr(ProcessInstanceModel, attribute).asc()
)
elif attribute in instance_metadata_aliases: elif attribute in instance_metadata_aliases:
if order_by_option.startswith('-'): if order_by_option.startswith("-"):
order_by_query_array.append(instance_metadata_aliases[attribute].value.desc()) order_by_query_array.append(
instance_metadata_aliases[attribute].value.desc()
)
else: else:
order_by_query_array.append(instance_metadata_aliases[attribute].value.asc()) order_by_query_array.append(
instance_metadata_aliases[attribute].value.asc()
)
process_instances = ( process_instances = (
process_instance_query.group_by(ProcessInstanceModel.id) process_instance_query.group_by(ProcessInstanceModel.id)
.add_columns(ProcessInstanceModel.id) .add_columns(ProcessInstanceModel.id)
.order_by( .order_by(*order_by_query_array)
*order_by_query_array
)
.paginate(page=page, per_page=per_page, error_out=False) .paginate(page=page, per_page=per_page, error_out=False)
) )

View File

@ -2665,6 +2665,7 @@ class TestProcessApi(BaseTest):
with_db_and_bpmn_file_cleanup: None, with_db_and_bpmn_file_cleanup: None,
with_super_admin_user: UserModel, with_super_admin_user: UserModel,
) -> None: ) -> None:
"""Test_process_instance_list_can_order_by_metadata."""
self.create_process_group( self.create_process_group(
client, with_super_admin_user, "test_group", "test_group" client, with_super_admin_user, "test_group", "test_group"
) )
@ -2714,8 +2715,8 @@ class TestProcessApi(BaseTest):
assert response.status_code == 200 assert response.status_code == 200
assert response.json is not None assert response.json is not None
assert len(response.json["results"]) == 2 assert len(response.json["results"]) == 2
assert response.json['results'][0]['id'] == process_instance_one.id assert response.json["results"][0]["id"] == process_instance_one.id
assert response.json['results'][1]['id'] == process_instance_two.id assert response.json["results"][1]["id"] == process_instance_two.id
report_metadata = { report_metadata = {
"columns": [ "columns": [
@ -2738,5 +2739,5 @@ class TestProcessApi(BaseTest):
assert response.status_code == 200 assert response.status_code == 200
assert response.json is not None assert response.json is not None
assert len(response.json["results"]) == 2 assert len(response.json["results"]) == 2
assert response.json['results'][1]['id'] == process_instance_one.id assert response.json["results"][1]["id"] == process_instance_one.id
assert response.json['results'][0]['id'] == process_instance_two.id assert response.json["results"][0]["id"] == process_instance_two.id

View File

@ -1027,7 +1027,7 @@ export default function ProcessInstanceListTable({
</ButtonSet> </ButtonSet>
</Column> </Column>
<Column sm={4} md={4} lg={8}> <Column sm={4} md={4} lg={8}>
{saveAsReportComponent()} {saveAsReportComponent()}
</Column> </Column>
</Grid> </Grid>
</> </>