Workflow spec cleanup needs a category_id

This commit is contained in:
mike cullerton 2021-08-31 12:17:25 -04:00
parent b92676ea75
commit ed57993f8d
2 changed files with 6 additions and 4 deletions

View File

@ -39,8 +39,9 @@ def all_specifications(libraries=False,standalone=False):
def add_workflow_specification(body):
WorkflowService.cleanup_workflow_spec_display_order()
count = session.query(WorkflowSpecModel).filter_by(category_id=body['category_id']).count()
category_id = body['category_id']
WorkflowService.cleanup_workflow_spec_display_order(category_id)
count = session.query(WorkflowSpecModel).filter_by(category_id=category_id).count()
body['display_order'] = count
new_spec: WorkflowSpecModel = WorkflowSpecModelSchema().load(body, session=session)
session.add(new_spec)
@ -151,7 +152,7 @@ def delete_workflow_specification(spec_id):
session.commit()
# Reorder the remaining specs
WorkflowService.cleanup_workflow_spec_display_order()
WorkflowService.cleanup_workflow_spec_display_order(category_id)
def reorder_workflow_specification(spec_id, direction):

View File

@ -987,10 +987,11 @@ class WorkflowService(object):
return ordered_categories
@staticmethod
def cleanup_workflow_spec_display_order():
def cleanup_workflow_spec_display_order(category_id):
# make sure we don't have gaps in display_order
new_order = 0
specs = session.query(WorkflowSpecModel).\
filter(WorkflowSpecModel.category_id == category_id).\
order_by(WorkflowSpecModel.display_order).all()
for spec in specs:
spec.display_order = new_order