dashboard: correct add tile ordering (#58528)

This commit is contained in:
Nicolas Roche 2021-11-10 11:50:09 +01:00
parent bbfc19618a
commit d49d0a7541
2 changed files with 10 additions and 1 deletions

View File

@ -78,7 +78,7 @@ class DashboardAddTileView(View):
order = (
Tile.objects.filter(dashboard=dashboard, user=request.user)
.aggregate(Max('order'))
.get('order_max')
.get('order__max')
)
tile.order = order + 1 if order is not None else 0
tile.save()

View File

@ -87,6 +87,15 @@ def test_add_to_dashboard_order(app, site):
assert Tile.objects.all()[2].cell.text == 'hello world (101)'
assert Tile.objects.all()[3].cell.text == 'hello world (102)'
cell = TextCell.objects.get(order=104)
app.get(reverse('combo-dashboard-add-tile', kwargs={'cell_reference': cell.get_reference()}))
assert Tile.objects.count() == 5
assert Tile.objects.all()[0].cell.text == 'hello world (103)'
assert Tile.objects.all()[1].cell.text == 'hello world (100)'
assert Tile.objects.all()[2].cell.text == 'hello world (101)'
assert Tile.objects.all()[3].cell.text == 'hello world (102)'
assert Tile.objects.all()[4].cell.text == 'hello world (104)'
def test_ajax_add_to_dashboard(app, site):
cell = TextCell.objects.get(order=100)