Merge pull request #2423 from normanjaeckel/NeedFullUpdate

Implemented need_full_update check. Fixed #2396.
This commit is contained in:
Emanuel Schütze 2016-09-23 15:00:17 +02:00 committed by GitHub
commit 5a70125922
6 changed files with 55 additions and 7 deletions

View File

@ -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()

View File

@ -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()

View File

@ -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):

View File

@ -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()

View File

@ -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:

View File

@ -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