misc: add support for manual ordering to workflow categories (#56533)

This commit is contained in:
Frédéric Péters 2021-08-31 19:59:46 +02:00
parent 0ee6821220
commit c05735d66d
3 changed files with 20 additions and 1 deletions

View File

@ -208,6 +208,23 @@ def test_workflows_category(pub):
workflow.refresh_from_storage()
assert str(workflow.category_id) == '1'
resp = app.get('/backoffice/workflows/categories/')
resp = resp.click('New Category')
resp.forms[0]['name'] = 'a second category'
resp.forms[0]['description'] = 'description of the category'
resp = resp.forms[0].submit('submit')
assert WorkflowCategory.get(2).name == 'a second category'
app.get('/backoffice/workflows/categories/update_order?order=2;1;')
categories = WorkflowCategory.select()
WorkflowCategory.sort_by_position(categories)
assert [x.id for x in categories] == ['2', '1']
app.get('/backoffice/workflows/categories/update_order?order=1;2;')
categories = WorkflowCategory.select()
WorkflowCategory.sort_by_position(categories)
assert [x.id for x in categories] == ['1', '2']
resp = app.get('/backoffice/workflows/categories/')
resp = resp.click('a new category')
resp = resp.click('Delete')

View File

@ -1889,7 +1889,8 @@ class WorkflowsDirectory(Directory):
else:
unused_workflows.append(workflow)
categories = sorted(WorkflowCategory.select(), key=lambda x: misc.simplify(x.name))
categories = self.category_class.select()
self.category_class.sort_by_position(categories)
if categories:
default_category = WorkflowCategory('Default')

View File

@ -167,6 +167,7 @@ class WorkflowCategory(Category):
('name', 'str'),
('url_name', 'str'),
('description', 'str'),
('position', 'int'),
]
@classmethod