diff --git a/CHANGELOG b/CHANGELOG index 920e4611e..25e0e3fb4 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -12,6 +12,7 @@ Agenda: - Fixed wrong sorting of last speakers [#3193]. - Fixed issue when sorting a new inserted speaker [#3210]. - New permission for managing lists of speakers [#3366]. +- Fixed multiple request on creation of agenda related items [#3341]. Motions: - New export dialog [#3185]. diff --git a/openslides/agenda/signals.py b/openslides/agenda/signals.py index 7fff95ea7..0980d9148 100644 --- a/openslides/agenda/signals.py +++ b/openslides/agenda/signals.py @@ -14,16 +14,25 @@ def listen_to_related_object_post_save(sender, instance, created, **kwargs): Receiver function to create agenda items. It is connected to the signal 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). + The agenda_item_update_information container may have fields like type, + parent or skip_autoupdate. + + Do not run caching and autoupdate if the instance as a key + skip_autoupdate in the agenda_item_update_information container. """ if hasattr(instance, 'get_agenda_title'): if created: + attrs = {} + if instance.agenda_item_update_information.get('type'): + attrs['type'] = instance.agenda_item_update_information.get('type') + if instance.agenda_item_update_information.get('parent'): + attrs['parent'] = instance.agenda_item_update_information.get('parent') + Item.objects.create(content_object=instance, **attrs) + # If the object is created, the related_object has to be sent again. - Item.objects.create(content_object=instance) - if not hasattr(instance, 'skip_autoupdate'): + if not instance.agenda_item_update_information.get('skip_autoupdate'): inform_changed_data(instance) - elif not hasattr(instance, 'skip_autoupdate'): + elif not instance.agenda_item_update_information.get('skip_autoupdate'): # If the object has changed, then also the agenda item has to be sent. inform_changed_data(instance.agenda_item) diff --git a/openslides/assignments/models.py b/openslides/assignments/models.py index ede9fe5d8..5f5257500 100644 --- a/openslides/assignments/models.py +++ b/openslides/assignments/models.py @@ -330,6 +330,11 @@ class Assignment(RESTModelMixin, models.Model): vote_results_dict[candidate].append(votes) return vote_results_dict + """ + Container for runtime information for agenda app (on create or update of this instance). + """ + agenda_item_update_information = {} + def get_agenda_title(self): return str(self) diff --git a/openslides/motions/models.py b/openslides/motions/models.py index 7f792ea36..37ac74d4a 100644 --- a/openslides/motions/models.py +++ b/openslides/motions/models.py @@ -628,6 +628,11 @@ class Motion(RESTModelMixin, models.Model): if self.recommendation is not None: self.set_state(self.recommendation) + """ + Container for runtime information for agenda app (on create or update of this instance). + """ + agenda_item_update_information = {} + def get_agenda_title(self): """ Return a simple title string for the agenda. @@ -895,6 +900,11 @@ class MotionBlock(RESTModelMixin, models.Model): id=self.pk) return super().delete(skip_autoupdate=skip_autoupdate, *args, **kwargs) # type: ignore + """ + Container for runtime information for agenda app (on create or update of this instance). + """ + agenda_item_update_information = {} + @property def agenda_item(self): """ diff --git a/openslides/motions/views.py b/openslides/motions/views.py index cc4679c79..8fdb8a21b 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -596,7 +596,7 @@ class CategoryViewSet(ModelViewSet): # Remove old identifiers for motion in motions: motion.identifier = None - motion.skip_autoupdate = True # This line is to skip agenda item autoupdate. See agenda/signals.py. + motion.agenda_item_update_information['skip_autoupdate'] = True # This line is to skip agenda item autoupdate. See agenda/signals.py. motion.save(skip_autoupdate=True) # Set new identifers and change identifiers of amendments. @@ -615,7 +615,7 @@ class CategoryViewSet(ModelViewSet): obj['new_identifier'], child.identifier, count=1) - child.skip_autoupdate = True # This line is to skip agenda item autoupdate. See agenda/signals.py. + child.agenda_item_update_information['skip_autoupdate'] = True # This line is to skip agenda item autoupdate. See agenda/signals.py. child.save(skip_autoupdate=True) instances.append(child) instances.append(child.agenda_item) diff --git a/openslides/topics/models.py b/openslides/topics/models.py index e31478c7d..d40227be8 100644 --- a/openslides/topics/models.py +++ b/openslides/topics/models.py @@ -54,6 +54,11 @@ class Topic(RESTModelMixin, models.Model): id=self.pk) return super().delete(skip_autoupdate=skip_autoupdate, *args, **kwargs) # type: ignore + """ + Container for runtime information for agenda app (on create or update of this instance). + """ + agenda_item_update_information = {} + @property def agenda_item(self): """