Merge pull request #3652 from emanuelschuetze/numberingCategory

Improved error handling of re-numbering motions of a category.
This commit is contained in:
Emanuel Schütze 2018-03-14 18:03:48 +01:00 committed by GitHub
commit b1d5fa21c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -618,6 +618,12 @@ class CategoryViewSet(ModelViewSet):
# Set new identifers and change identifiers of amendments. # Set new identifers and change identifiers of amendments.
for obj in motions_to_be_sorted: for obj in motions_to_be_sorted:
if Motion.objects.filter(identifier=obj['new_identifier']).exists():
raise ValidationError({
'detail':
_('Numbering aborted because the motion identifier "%s" already exists outside of this category.') %
obj['new_identifier']
})
motion = obj['motion'] motion = obj['motion']
motion.identifier = obj['new_identifier'] motion.identifier = obj['new_identifier']
motion.identifier_number = obj['number'] motion.identifier_number = obj['number']
@ -626,7 +632,7 @@ class CategoryViewSet(ModelViewSet):
instances.append(motion.agenda_item) instances.append(motion.agenda_item)
# Change identifiers of amendments. # Change identifiers of amendments.
for child in motion.get_amendments_deep(): for child in motion.get_amendments_deep():
if child.identifier.startswith(obj['old_identifier']): if child.identifier and child.identifier.startswith(obj['old_identifier']):
child.identifier = re.sub( child.identifier = re.sub(
obj['old_identifier'], obj['old_identifier'],
obj['new_identifier'], obj['new_identifier'],