Merge pull request #4667 from FinnStutzenstein/motionNumberingFIx

Fix numbering with amendments
This commit is contained in:
Emanuel Schütze 2019-05-07 17:38:20 +02:00 committed by GitHub
commit 294ccf7301
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1224,7 +1224,7 @@ class CategoryViewSet(ModelViewSet):
Send POST {'motions': [<list of motion ids>]} to sort the given Send POST {'motions': [<list of motion ids>]} to sort the given
motions in a special order. Ids of motions which do not belong to motions in a special order. Ids of motions which do not belong to
the category are just ignored. Send just POST {} to sort all the category are just ignored. Send just POST {} to sort all
motions in the category by database id. motions in the category ordered by their category weight.
Amendments will get a new identifier prefix if the old prefix matches Amendments will get a new identifier prefix if the old prefix matches
the old parent motion identifier. the old parent motion identifier.
@ -1241,12 +1241,14 @@ class CategoryViewSet(ModelViewSet):
# Prepare ordered list of motions. # Prepare ordered list of motions.
if not category.prefix: if not category.prefix:
prefix = "" category_prefix = ""
elif without_blank: elif without_blank:
prefix = category.prefix category_prefix = category.prefix
else: else:
prefix = f"{category.prefix} " category_prefix = f"{category.prefix} "
motions = category.motion_set.all()
# get motions
motions = category.motion_set.order_by("category_weight")
motion_list = request.data.get("motions") motion_list = request.data.get("motions")
if motion_list: if motion_list:
motion_dict = {} motion_dict = {}
@ -1261,12 +1263,16 @@ class CategoryViewSet(ModelViewSet):
# Collect old and new identifiers. # Collect old and new identifiers.
motions_to_be_sorted = [] motions_to_be_sorted = []
for motion in motions: for motion in motions:
prefix = category_prefix
# Change prefix for amendments
if motion.is_amendment(): if motion.is_amendment():
parent_identifier = motion.parent.identifier or "" parent_identifier = motion.parent.identifier or ""
if without_blank: if without_blank:
prefix = f"{parent_identifier}{config['motions_amendments_prefix']}" prefix = f"{parent_identifier}{config['motions_amendments_prefix']}"
else: else:
prefix = f"{parent_identifier} {config['motions_amendments_prefix']} " prefix = f"{parent_identifier} {config['motions_amendments_prefix']} "
else:
number += 1 number += 1
new_identifier = ( new_identifier = (
f"{prefix}{motion.extend_identifier_number(number)}" f"{prefix}{motion.extend_identifier_number(number)}"