Added possibility to sort motions in category numbering view.
This commit is contained in:
parent
243ef7ae5d
commit
b0070d13b9
@ -21,7 +21,7 @@ Core:
|
|||||||
|
|
||||||
Motions:
|
Motions:
|
||||||
- Added origin field.
|
- Added origin field.
|
||||||
- Added button to number all motions in a category.
|
- Added button to sort and number all motions in a category.
|
||||||
|
|
||||||
Users:
|
Users:
|
||||||
- Added field is_committee and new default group Committees.
|
- Added field is_committee and new default group Committees.
|
||||||
|
@ -307,6 +307,11 @@ class CategoryViewSet(ModelViewSet):
|
|||||||
Special view endpoint to number all motions in this category.
|
Special view endpoint to number all motions in this category.
|
||||||
|
|
||||||
Only managers can use this view.
|
Only managers can use this view.
|
||||||
|
|
||||||
|
Send POST {'motions': [<list of motion ids>]} to sort the given
|
||||||
|
motions in a special order. Ids of motions which do not belong to
|
||||||
|
the category are just ignored. Send just POST {} to sort all
|
||||||
|
motions in the category by id.
|
||||||
"""
|
"""
|
||||||
category = self.get_object()
|
category = self.get_object()
|
||||||
number = 0
|
number = 0
|
||||||
@ -314,13 +319,20 @@ class CategoryViewSet(ModelViewSet):
|
|||||||
prefix = ''
|
prefix = ''
|
||||||
else:
|
else:
|
||||||
prefix = '%s ' % category.prefix
|
prefix = '%s ' % category.prefix
|
||||||
|
motions = category.motion_set.all()
|
||||||
|
motion_list = request.data.get('motions')
|
||||||
|
if motion_list:
|
||||||
|
motion_dict = {}
|
||||||
|
for motion in motions.filter(id__in=motion_list):
|
||||||
|
motion_dict[motion.pk] = motion
|
||||||
|
motions = [motion_dict[pk] for pk in motion_list]
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for motion in category.motion_set.all():
|
for motion in motions:
|
||||||
motion.identifier = None
|
motion.identifier = None
|
||||||
motion.save()
|
motion.save()
|
||||||
|
|
||||||
for motion in category.motion_set.all():
|
for motion in motions:
|
||||||
if motion.is_amendment():
|
if motion.is_amendment():
|
||||||
parent_identifier = motion.parent.identifier or ''
|
parent_identifier = motion.parent.identifier or ''
|
||||||
prefix = '%s %s ' % (parent_identifier, config['motions_amendments_prefix'])
|
prefix = '%s %s ' % (parent_identifier, config['motions_amendments_prefix'])
|
||||||
|
@ -487,3 +487,21 @@ class NumberMotionsInCategory(TestCase):
|
|||||||
self.assertEqual(response.data, {'detail': 'All motions in category test_cateogory_name_zah6Ahd4Ifofaeree6ai numbered successfully.'})
|
self.assertEqual(response.data, {'detail': 'All motions in category test_cateogory_name_zah6Ahd4Ifofaeree6ai numbered successfully.'})
|
||||||
self.assertEqual(Motion.objects.get(pk=self.motion.pk).identifier, 'test_prefix_ahz6tho2mooH8 1')
|
self.assertEqual(Motion.objects.get(pk=self.motion.pk).identifier, 'test_prefix_ahz6tho2mooH8 1')
|
||||||
self.assertEqual(Motion.objects.get(pk=self.motion_2.pk).identifier, 'test_prefix_ahz6tho2mooH8 2')
|
self.assertEqual(Motion.objects.get(pk=self.motion_2.pk).identifier, 'test_prefix_ahz6tho2mooH8 2')
|
||||||
|
|
||||||
|
def test_numbering_with_given_order(self):
|
||||||
|
self.motion_3 = Motion(
|
||||||
|
title='test_title_eeb0kua5ciike4su2auJ',
|
||||||
|
text='test_text_ahshuGhaew3eim8yoht7',
|
||||||
|
category=self.category)
|
||||||
|
self.motion_3.save()
|
||||||
|
self.motion_3.identifier = ''
|
||||||
|
self.motion_3.save()
|
||||||
|
response = self.client.post(
|
||||||
|
reverse('category-numbering', args=[self.category.pk]),
|
||||||
|
{'motions': [3, 2]},
|
||||||
|
format='json')
|
||||||
|
self.assertEqual(response.status_code, status.HTTP_200_OK)
|
||||||
|
self.assertEqual(response.data, {'detail': 'All motions in category test_cateogory_name_zah6Ahd4Ifofaeree6ai numbered successfully.'})
|
||||||
|
self.assertEqual(Motion.objects.get(pk=self.motion.pk).identifier, None)
|
||||||
|
self.assertEqual(Motion.objects.get(pk=self.motion_2.pk).identifier, 'test_prefix_ahz6tho2mooH8 2')
|
||||||
|
self.assertEqual(Motion.objects.get(pk=self.motion_3.pk).identifier, 'test_prefix_ahz6tho2mooH8 1')
|
||||||
|
Loading…
Reference in New Issue
Block a user