From 3bf1f24a4a31b63ff0b5e98fe28eaffb338497af Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 8 Sep 2013 10:38:50 +0200 Subject: [PATCH] Fixed wrong ordering of agenda items after order change Fixed #875 --- openslides/agenda/views.py | 7 ++++--- tests/agenda/tests.py | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/openslides/agenda/views.py b/openslides/agenda/views.py index 9333de7c3..5a585c653 100644 --- a/openslides/agenda/views.py +++ b/openslides/agenda/views.py @@ -95,7 +95,6 @@ class Overview(TemplateView): @transaction.commit_manually def post(self, request, *args, **kwargs): - context = self.get_context_data(**kwargs) if not request.user.has_perm('agenda.can_manage_agenda'): messages.error( request, @@ -116,9 +115,11 @@ class Overview(TemplateView): transaction.rollback() messages.error( request, _('Errors when reordering of the agenda')) - return self.render_to_response(context) - Item.objects.rebuild() + break + else: + Item.objects.rebuild() # TODO: assure, that it is a valid tree + context = self.get_context_data(**kwargs) transaction.commit() return self.render_to_response(context) diff --git a/tests/agenda/tests.py b/tests/agenda/tests.py index 0a9d2bb7b..11a14ee71 100644 --- a/tests/agenda/tests.py +++ b/tests/agenda/tests.py @@ -198,6 +198,25 @@ class ViewTest(TestCase): response = c.get('/agenda/%s/' % item.id) self.assertContains(response, 'quai5OTeephaequ0xei0') + def test_change_item_order(self): + data = { + 'i1-self': 1, + 'i1-weight': 50, + 'i1-parent': 0, + 'i2-self': 2, + 'i2-weight': 50, + 'i2-parent': 1} + response = self.adminClient.post('/agenda/', data) + + # Test values in response. + items = response.context['items'] + self.assertIsNone(items[0].parent) + self.assertEqual(items[1].parent_id, 1) + + # Test values in DB + self.assertIsNone(Item.objects.get(pk=1).parent) + self.assertEqual(Item.objects.get(pk=2).parent_id, 1) + class ConfigTest(TestCase): def setUp(self):