Fixed wrong ordering of agenda items after order change

Fixed #875
This commit is contained in:
Oskar Hahn 2013-09-08 10:38:50 +02:00
parent 61a449cc77
commit 3bf1f24a4a
2 changed files with 23 additions and 3 deletions

View File

@ -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)

View File

@ -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):