Skip to content
Snippets Groups Projects
Verified Commit cb2a8f13 authored by Erwan Rouchet's avatar Erwan Rouchet
Browse files

Fix max orderings in CreateElementChildren

parent 1d1864cd
No related branches found
No related tags found
1 merge request!2429Fix max orderings in CreateElementChildren
......@@ -1006,6 +1006,7 @@ class ElementChildrenCreateSerializer(serializers.Serializer):
ElementPath.objects
.using("default")
.filter(path__in=new_parent_paths)
.values("path")
.annotate(max_ordering=Max("ordering") + 1)
.values_list("path", "max_ordering")
)
......
......@@ -149,6 +149,8 @@ class TestElementChildrenCreate(FixtureAPITestCase):
other_parent = self.corpus.elements.create(type=self.volume2.type, name="Other parent")
self.page2.add_parent(other_parent)
self.page3.add_parent(other_parent)
page4 = self.corpus.elements.create(type=self.page3.type, name="Page 4")
page4.add_parent(self.volume2)
self.assertQuerySetEqual(
self.volume2.paths.values_list("path", flat=True),
......@@ -170,6 +172,10 @@ class TestElementChildrenCreate(FixtureAPITestCase):
([self.volume1.id, self.volume2.id], 2),
],
)
self.assertQuerySetEqual(
page4.paths.values_list("path", "ordering"),
[([self.volume1.id, self.volume2.id], 3)],
)
with force_constraints_immediate(), self.assertNumQueries(10):
response = self.client.post(
......@@ -187,7 +193,7 @@ class TestElementChildrenCreate(FixtureAPITestCase):
self.assertQuerySetEqual(
self.page1.paths.values_list("path", "ordering"),
# The top-level path is removed, and the page is back in the volume, in last position
[([self.volume1.id, self.volume2.id], 5)],
[([self.volume1.id, self.volume2.id], 6)],
)
self.assertQuerySetEqual(
self.page2.paths.values_list("path", "ordering").order_by("ordering"),
......@@ -195,7 +201,7 @@ class TestElementChildrenCreate(FixtureAPITestCase):
# The path to the other parent is left untouched
([other_parent.id], 0),
# The page is back in the volume, in second position
([self.volume1.id, self.volume2.id], 4),
([self.volume1.id, self.volume2.id], 5),
],
)
self.assertQuerySetEqual(
......@@ -204,6 +210,6 @@ class TestElementChildrenCreate(FixtureAPITestCase):
# The path to the other parent is left untouched
([other_parent.id], 1),
# The last page got reordered
([self.volume1.id, self.volume2.id], 3),
([self.volume1.id, self.volume2.id], 4),
],
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment