First pass at reorder spec code.
Still need to return list of specs Still need to work on spec categories
This commit is contained in:
parent
f639e101b7
commit
41414e39c8
|
@ -145,7 +145,24 @@ def delete_workflow_specification(spec_id):
|
|||
|
||||
|
||||
def reorder_workflow_specification(spec_id, direction):
|
||||
pass
|
||||
# TODO: Need to return list of specs
|
||||
# TODO: Maybe move some of this code to services.workflow_service
|
||||
if direction not in ('up', 'down'):
|
||||
raise ApiError(code='bad_direction',
|
||||
message='The direction must be `up` or `down`.')
|
||||
spec = session.query(WorkflowSpecModel).filter(WorkflowSpecModel.id == spec_id).first()
|
||||
category_id = spec.category_id
|
||||
if direction == 'up':
|
||||
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
|
||||
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()
|
||||
|
||||
|
||||
def get_workflow_from_spec(spec_id):
|
||||
|
|
Loading…
Reference in New Issue