From 79d69068f5b81074d40d94d1f3ad915fad54687e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emanuel=20Sch=C3=BCtze?= Date: Wed, 14 Mar 2018 13:11:36 +0100 Subject: [PATCH] Improved error handling of re-numbering motions of a category. --- openslides/motions/views.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/openslides/motions/views.py b/openslides/motions/views.py index b84fad105..c9b1b130a 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -618,6 +618,12 @@ class CategoryViewSet(ModelViewSet): # Set new identifers and change identifiers of amendments. 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.identifier = obj['new_identifier'] motion.identifier_number = obj['number'] @@ -626,7 +632,7 @@ class CategoryViewSet(ModelViewSet): instances.append(motion.agenda_item) # Change identifiers of amendments. 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( obj['old_identifier'], obj['new_identifier'],