Make sure we don't try to move past the top or bottom of the list.

This commit is contained in:
mike cullerton 2021-08-30 11:42:44 -04:00
parent 070a9c9350
commit a99818b177
1 changed files with 20 additions and 14 deletions

View File

@ -940,18 +940,21 @@ class WorkflowService(object):
filter(WorkflowSpecModel.category_id == category_id). \
filter(WorkflowSpecModel.display_order == spec.display_order - 1). \
first()
neighbor.display_order += 1
spec.display_order -= 1
if neighbor:
neighbor.display_order += 1
spec.display_order -= 1
if direction == 'down':
neighbor = session.query(WorkflowSpecModel). \
filter(WorkflowSpecModel.category_id == category_id). \
filter(WorkflowSpecModel.display_order == spec.display_order + 1). \
first()
neighbor.display_order -= 1
spec.display_order += 1
session.add(spec)
session.add(neighbor)
session.commit()
if neighbor:
neighbor.display_order -= 1
spec.display_order += 1
if neighbor:
session.add(spec)
session.add(neighbor)
session.commit()
ordered_specs = session.query(WorkflowSpecModel). \
filter(WorkflowSpecModel.category_id == category_id). \
order_by(WorkflowSpecModel.display_order).all()
@ -965,17 +968,20 @@ class WorkflowService(object):
neighbor = session.query(WorkflowSpecCategoryModel).\
filter(WorkflowSpecCategoryModel.display_order == category.display_order - 1).\
first()
neighbor.display_order += 1
category.display_order -= 1
if neighbor:
neighbor.display_order += 1
category.display_order -= 1
if direction == 'down':
neighbor = session.query(WorkflowSpecCategoryModel).\
filter(WorkflowSpecCategoryModel.display_order == category.display_order + 1).\
first()
neighbor.display_order -= 1
category.display_order += 1
session.add(neighbor)
session.add(category)
session.commit()
if neighbor:
neighbor.display_order -= 1
category.display_order += 1
if neighbor:
session.add(neighbor)
session.add(category)
session.commit()
ordered_categories = session.query(WorkflowSpecCategoryModel).\
order_by(WorkflowSpecCategoryModel.display_order).all()
return ordered_categories