Move display_order cleanup to their own methods
This commit is contained in:
parent
b76f45368b
commit
f6816a2e42
|
@ -145,16 +145,7 @@ def delete_workflow_specification(spec_id):
|
|||
session.commit()
|
||||
|
||||
# Reorder the remaining specs
|
||||
new_order = 0
|
||||
wf_specs = session.query(WorkflowSpecModel).\
|
||||
filter(WorkflowSpecModel.category_id == category_id).\
|
||||
order_by(WorkflowSpecModel.display_order).\
|
||||
all()
|
||||
for wf_spec_model in wf_specs:
|
||||
wf_spec_model.display_order = new_order
|
||||
session.add(wf_spec_model)
|
||||
new_order += 1
|
||||
session.commit()
|
||||
WorkflowService.cleanup_workflow_spec_display_order()
|
||||
|
||||
|
||||
def reorder_workflow_specification(spec_id, direction):
|
||||
|
@ -354,13 +345,7 @@ def delete_workflow_spec_category(cat_id):
|
|||
session.query(WorkflowSpecCategoryModel).filter_by(id=cat_id).delete()
|
||||
session.commit()
|
||||
# Reorder the remaining categories
|
||||
remaining = session.query(WorkflowSpecCategoryModel).order_by(WorkflowSpecCategoryModel.display_order).all()
|
||||
new_order = 0
|
||||
for category_model in remaining:
|
||||
category_model.display_order = new_order
|
||||
session.add(category_model)
|
||||
new_order += 1
|
||||
session.commit()
|
||||
WorkflowService.cleanup_workflow_spec_category_display_order()
|
||||
|
||||
|
||||
def reorder_workflow_spec_category(cat_id, direction):
|
||||
|
|
|
@ -985,3 +985,27 @@ class WorkflowService(object):
|
|||
ordered_categories = session.query(WorkflowSpecCategoryModel).\
|
||||
order_by(WorkflowSpecCategoryModel.display_order).all()
|
||||
return ordered_categories
|
||||
|
||||
@staticmethod
|
||||
def cleanup_workflow_spec_display_order():
|
||||
# make sure we don't have gaps in display_order
|
||||
new_order = 0
|
||||
specs = session.query(WorkflowSpecModel).\
|
||||
order_by(WorkflowSpecModel.display_order).all()
|
||||
for spec in specs:
|
||||
spec.display_order = new_order
|
||||
session.add(spec)
|
||||
new_order += 1
|
||||
session.commit()
|
||||
|
||||
@staticmethod
|
||||
def cleanup_workflow_spec_category_display_order():
|
||||
# make sure we don't have gaps in display_order
|
||||
new_order = 0
|
||||
categories = session.query(WorkflowSpecCategoryModel).\
|
||||
order_by(WorkflowSpecCategoryModel.display_order).all()
|
||||
for category in categories:
|
||||
category.display_order = new_order
|
||||
session.add(category)
|
||||
new_order += 1
|
||||
session.commit()
|
||||
|
|
Loading…
Reference in New Issue