From 834ed77a2ca9403444af709ecc61bf2934c2aedb Mon Sep 17 00:00:00 2001 From: FinnStutzenstein Date: Fri, 3 Nov 2017 09:32:43 +0100 Subject: [PATCH] Bundle autoupdates for beginning a speech --- openslides/agenda/models.py | 19 ++++++++++++------- openslides/core/models.py | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/openslides/agenda/models.py b/openslides/agenda/models.py index 8386daa86..de3247321 100644 --- a/openslides/agenda/models.py +++ b/openslides/agenda/models.py @@ -12,6 +12,7 @@ from django.utils.translation import ugettext_lazy from openslides.core.config import config from openslides.core.models import Countdown, Projector +from openslides.utils.autoupdate import inform_changed_data from openslides.utils.exceptions import OpenSlidesError from openslides.utils.models import RESTModelMixin from openslides.utils.utils import to_roman @@ -422,31 +423,35 @@ class Speaker(RESTModelMixin, models.Model): except Speaker.DoesNotExist: pass else: - current_speaker.end_speech() + # Do not send an autoupdate for the countdown and the item. This is done + # by saving the item and countdown later. + current_speaker.end_speech(skip_autoupdate=True) self.weight = None self.begin_time = timezone.now() - self.save() + self.save() # Here, the item is saved and causes an autoupdate. if config['agenda_couple_countdown_and_speakers']: countdown, created = Countdown.objects.get_or_create(pk=1, defaults={ 'default_time': config['projector_default_countdown'], 'countdown_time': config['projector_default_countdown']}) if not created: - countdown.control(action='reset') - countdown.control(action='start') + countdown.control(action='reset', skip_autoupdate=True) + countdown.control(action='start', skip_autoupdate=True) - def end_speech(self): + inform_changed_data(countdown) # Here, the autoupdate for the countdown is triggered. + + def end_speech(self, skip_autoupdate=False): """ The speech is finished. Set the time to now. """ self.end_time = timezone.now() - self.save() + self.save(skip_autoupdate=skip_autoupdate) if config['agenda_couple_countdown_and_speakers']: try: countdown = Countdown.objects.get(pk=1) except Countdown.DoesNotExist: pass # Do not create a new countdown on stop action else: - countdown.control(action='reset') + countdown.control(action='reset', skip_autoupdate=skip_autoupdate) def get_root_rest_element(self): """ diff --git a/openslides/core/models.py b/openslides/core/models.py index 4ea1191e7..abb0c09c1 100644 --- a/openslides/core/models.py +++ b/openslides/core/models.py @@ -365,7 +365,7 @@ class Countdown(RESTModelMixin, models.Model): id=self.pk) return super().delete(skip_autoupdate=skip_autoupdate, *args, **kwargs) # type: ignore - def control(self, action): + def control(self, action, skip_autoupdate=False): if action not in ('start', 'stop', 'reset'): raise ValueError("Action must be 'start', 'stop' or 'reset', not {}.".format(action)) @@ -378,4 +378,4 @@ class Countdown(RESTModelMixin, models.Model): else: # reset self.running = False self.countdown_time = self.default_time - self.save() + self.save(skip_autoupdate=skip_autoupdate)