Merge pull request #3749 from FinnStutzenstein/motionNumberingException

Removed the ValidationError in motion numbering (fixed #3680)
This commit is contained in:
Emanuel Schütze 2018-06-12 13:06:29 +02:00 committed by GitHub
commit 97bf5adc6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -617,6 +617,7 @@ class CategoryViewSet(ModelViewSet):
motions = [motion_dict[pk] for pk in motion_list] motions = [motion_dict[pk] for pk in motion_list]
# Change identifiers. # Change identifiers.
error_message = None
try: try:
with transaction.atomic(): with transaction.atomic():
# Collect old and new identifiers. # Collect old and new identifiers.
@ -647,11 +648,9 @@ 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(): if Motion.objects.filter(identifier=obj['new_identifier']).exists():
raise ValidationError({ # Set the error message and let the code run into an IntegrityError
'detail': error_message = _('Numbering aborted because the motion identifier "%s" '
_('Numbering aborted because the motion identifier "%s" already exists outside of this category.') % 'already exists outside of this category.') % obj['new_identifier']
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']
@ -672,9 +671,10 @@ class CategoryViewSet(ModelViewSet):
instances.append(child) instances.append(child)
instances.append(child.agenda_item) instances.append(child.agenda_item)
except IntegrityError: except IntegrityError:
message = _('Error: At least one identifier of this category does ' if error_message is None:
'already exist in another category.') error_message = _('Error: At least one identifier of this category does '
response = Response({'detail': message}, status=400) 'already exist in another category.')
response = Response({'detail': error_message}, status=400)
else: else:
inform_changed_data(instances) inform_changed_data(instances)
message = _('All motions in category {category} numbered ' message = _('All motions in category {category} numbered '