Merge pull request #2731 from normanjaeckel/MotionNumberingSpeed
Improved speed of motion numbering.
This commit is contained in:
commit
224ba797a2
@ -9,13 +9,17 @@ def listen_to_related_object_post_save(sender, instance, created, **kwargs):
|
|||||||
"""
|
"""
|
||||||
Receiver function to create agenda items. It is connected to the signal
|
Receiver function to create agenda items. It is connected to the signal
|
||||||
django.db.models.signals.post_save during app loading.
|
django.db.models.signals.post_save during app loading.
|
||||||
|
|
||||||
|
Do not run caching and autoupdate if the instance as an attribute
|
||||||
|
skip_autoupdate (regardless of its truthy or falsy conent).
|
||||||
"""
|
"""
|
||||||
if hasattr(instance, 'get_agenda_title'):
|
if hasattr(instance, 'get_agenda_title'):
|
||||||
if created:
|
if created:
|
||||||
# If the object is created, the related_object has to be sent again.
|
# If the object is created, the related_object has to be sent again.
|
||||||
Item.objects.create(content_object=instance)
|
Item.objects.create(content_object=instance)
|
||||||
inform_changed_data(instance)
|
if not hasattr(instance, 'skip_autoupdate'):
|
||||||
else:
|
inform_changed_data(instance)
|
||||||
|
elif not hasattr(instance, 'skip_autoupdate'):
|
||||||
# If the object has changed, then also the agenda item has to be sent.
|
# If the object has changed, then also the agenda item has to be sent.
|
||||||
inform_changed_data(instance.agenda_item)
|
inform_changed_data(instance.agenda_item)
|
||||||
|
|
||||||
|
@ -420,11 +420,13 @@ class CategoryViewSet(ModelViewSet):
|
|||||||
motion_dict[motion.pk] = motion
|
motion_dict[motion.pk] = motion
|
||||||
motions = [motion_dict[pk] for pk in motion_list]
|
motions = [motion_dict[pk] for pk in motion_list]
|
||||||
|
|
||||||
|
instances = []
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
for motion in motions:
|
for motion in motions:
|
||||||
motion.identifier = None
|
motion.identifier = None
|
||||||
motion.save()
|
motion.skip_autoupdate = True # This line is to skip agenda item autoupdate. See agenda/signals.py.
|
||||||
|
motion.save(skip_autoupdate=True)
|
||||||
|
|
||||||
for motion in motions:
|
for motion in motions:
|
||||||
if motion.is_amendment():
|
if motion.is_amendment():
|
||||||
@ -434,12 +436,15 @@ class CategoryViewSet(ModelViewSet):
|
|||||||
identifier = '%s%s' % (prefix, motion.extend_identifier_number(number))
|
identifier = '%s%s' % (prefix, motion.extend_identifier_number(number))
|
||||||
motion.identifier = identifier
|
motion.identifier = identifier
|
||||||
motion.identifier_number = number
|
motion.identifier_number = number
|
||||||
motion.save()
|
motion.save(skip_autoupdate=True)
|
||||||
|
instances.append(motion)
|
||||||
|
instances.append(motion.agenda_item)
|
||||||
except IntegrityError:
|
except IntegrityError:
|
||||||
message = _('Error: At least one identifier of this category does '
|
message = _('Error: At least one identifier of this category does '
|
||||||
'already exist in another category.')
|
'already exist in another category.')
|
||||||
response = Response({'detail': message}, status_code=400)
|
response = Response({'detail': message}, status_code=400)
|
||||||
else:
|
else:
|
||||||
|
inform_changed_data(instances)
|
||||||
message = _('All motions in category {category} numbered '
|
message = _('All motions in category {category} numbered '
|
||||||
'successfully.').format(category=category)
|
'successfully.').format(category=category)
|
||||||
response = Response({'detail': message})
|
response = Response({'detail': message})
|
||||||
|
Loading…
Reference in New Issue
Block a user