From dc404d21f6a3698a7e90b42d694c91e5f73adfe3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Fri, 23 Sep 2016 13:12:02 +0200 Subject: [PATCH] Implemented need_full_update check. Fixed #2396. --- openslides/agenda/projector.py | 5 +++++ openslides/assignments/projector.py | 9 +++++++++ openslides/core/models.py | 27 ++++++++++++++++++++++----- openslides/motions/projector.py | 8 ++++++++ openslides/utils/autoupdate.py | 4 ++-- openslides/utils/projector.py | 9 +++++++++ 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/openslides/agenda/projector.py b/openslides/agenda/projector.py index 3e0ac4143..07c69b8bb 100644 --- a/openslides/agenda/projector.py +++ b/openslides/agenda/projector.py @@ -59,3 +59,8 @@ class ListOfSpeakersSlide(ProjectorElement): for speaker in query: # Yield last speakers yield speaker.user + + def need_full_update_for_this(self, collection_element): + # Full update if item changes because then we may have new speakers + # and therefor need new users. + return collection_element.collection_string == Item.get_collection_string() diff --git a/openslides/assignments/projector.py b/openslides/assignments/projector.py index 74608ce42..d4121f852 100644 --- a/openslides/assignments/projector.py +++ b/openslides/assignments/projector.py @@ -23,7 +23,16 @@ class AssignmentSlide(ProjectorElement): yield assignment yield assignment.agenda_item for user in assignment.related_users.all(): + # Yield user instances of current candidates (i. e. future + # poll participants) and elected persons (i. e. former poll + # participants). yield user for poll in assignment.polls.all().prefetch_related('options'): + # Yield user instances of the participants of all polls. for option in poll.options.all(): yield option.candidate + + def need_full_update_for_this(self, collection_element): + # Full update if assignment changes because then we may have new + # candidates and therefor need new users. + return collection_element.collection_string == Assignment.get_collection_string() diff --git a/openslides/core/models.py b/openslides/core/models.py index 2b6dfc2d0..e74272e12 100644 --- a/openslides/core/models.py +++ b/openslides/core/models.py @@ -128,8 +128,8 @@ class Projector(RESTModelMixin, models.Model): Returns True if this collection element is shown on this projector. """ for requirement in self.get_all_requirements(): - if (requirement.get_collection_string() == collection_element['collection_string'] and - requirement.pk == collection_element['id']): + if (requirement.get_collection_string() == collection_element.collection_string and + requirement.pk == collection_element.id): result = True break else: @@ -147,9 +147,26 @@ class Projector(RESTModelMixin, models.Model): result.append(projector) return result - def need_full_update_for(self, collection_element): - # TODO: Implement this for all ProjectorElements (also for config values!) - return True + def need_full_update_for_this(self, collection_element): + """ + Returns True if this projector needs to be updated with all + instances as defined in get_all_requirements() because one active + projector element requires this. + """ + # Get all elements from all apps. + elements = {} + for element in ProjectorElement.get_all(): + elements[element.name] = element + + for key, value in self.config.items(): + element = elements.get(value['name']) + if element is not None and element.need_full_update_for_this(collection_element): + result = True + break + else: + result = False + + return result class Tag(RESTModelMixin, models.Model): diff --git a/openslides/motions/projector.py b/openslides/motions/projector.py index 001464b0f..efee87177 100644 --- a/openslides/motions/projector.py +++ b/openslides/motions/projector.py @@ -25,3 +25,11 @@ class MotionSlide(ProjectorElement): yield motion.state.workflow yield from motion.submitters.all() yield from motion.supporters.all() + + def need_full_update_for_this(self, collection_element): + # Full update if motion changes because then we may have new + # submitters or supporters and therefor need new users. + # + # Add some logic here if we support live changing of workflows later. + # + return collection_element.collection_string == Motion.get_collection_string() diff --git a/openslides/utils/autoupdate.py b/openslides/utils/autoupdate.py index 5546954d6..0a5807b45 100644 --- a/openslides/utils/autoupdate.py +++ b/openslides/utils/autoupdate.py @@ -135,12 +135,12 @@ def send_data(message): send_all = False else: # Other elements are only send to the projector they are currently shown - projectors = Projector.get_projectors_that_show_this(message) + projectors = Projector.get_projectors_that_show_this(collection_element) send_all = None # The decission is done later for projector in projectors: if send_all is None: - send_all = projector.need_full_update_for(message) + send_all = projector.need_full_update_for_this(collection_element) if send_all: output = get_projector_element_data(projector) else: diff --git a/openslides/utils/projector.py b/openslides/utils/projector.py index 053c43e2f..89ae0a6a4 100644 --- a/openslides/utils/projector.py +++ b/openslides/utils/projector.py @@ -72,3 +72,12 @@ class ProjectorElement(object, metaclass=SignalConnectMetaClass): element. The config_entry has to be given. """ return () + + def need_full_update_for_this(self, collection_element): + """ + Returns True if this projector element needs to be updated with all + instances as defined in get_requirements(). The given + collection_element contains information about the changed instance. + Default is False. + """ + return False