Merge pull request #3469 from FinnStutzenstein/CountdownRace

Bundle autoupdates for beginning a speech
This commit is contained in:
Emanuel Schütze 2017-11-03 10:47:22 +01:00 committed by GitHub
commit 4cbf7d6c9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -12,6 +12,7 @@ from django.utils.translation import ugettext_lazy
from openslides.core.config import config from openslides.core.config import config
from openslides.core.models import Countdown, Projector from openslides.core.models import Countdown, Projector
from openslides.utils.autoupdate import inform_changed_data
from openslides.utils.exceptions import OpenSlidesError from openslides.utils.exceptions import OpenSlidesError
from openslides.utils.models import RESTModelMixin from openslides.utils.models import RESTModelMixin
from openslides.utils.utils import to_roman from openslides.utils.utils import to_roman
@ -422,31 +423,35 @@ class Speaker(RESTModelMixin, models.Model):
except Speaker.DoesNotExist: except Speaker.DoesNotExist:
pass pass
else: 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.weight = None
self.begin_time = timezone.now() 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']: if config['agenda_couple_countdown_and_speakers']:
countdown, created = Countdown.objects.get_or_create(pk=1, defaults={ countdown, created = Countdown.objects.get_or_create(pk=1, defaults={
'default_time': config['projector_default_countdown'], 'default_time': config['projector_default_countdown'],
'countdown_time': config['projector_default_countdown']}) 'countdown_time': config['projector_default_countdown']})
if not created: if not created:
countdown.control(action='reset') countdown.control(action='reset', skip_autoupdate=True)
countdown.control(action='start') 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. The speech is finished. Set the time to now.
""" """
self.end_time = timezone.now() self.end_time = timezone.now()
self.save() self.save(skip_autoupdate=skip_autoupdate)
if config['agenda_couple_countdown_and_speakers']: if config['agenda_couple_countdown_and_speakers']:
try: try:
countdown = Countdown.objects.get(pk=1) countdown = Countdown.objects.get(pk=1)
except Countdown.DoesNotExist: except Countdown.DoesNotExist:
pass # Do not create a new countdown on stop action pass # Do not create a new countdown on stop action
else: else:
countdown.control(action='reset') countdown.control(action='reset', skip_autoupdate=skip_autoupdate)
def get_root_rest_element(self): def get_root_rest_element(self):
""" """

View File

@ -365,7 +365,7 @@ class Countdown(RESTModelMixin, models.Model):
id=self.pk) id=self.pk)
return super().delete(skip_autoupdate=skip_autoupdate, *args, **kwargs) # type: ignore 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'): if action not in ('start', 'stop', 'reset'):
raise ValueError("Action must be 'start', 'stop' or 'reset', not {}.".format(action)) raise ValueError("Action must be 'start', 'stop' or 'reset', not {}.".format(action))
@ -378,4 +378,4 @@ class Countdown(RESTModelMixin, models.Model):
else: # reset else: # reset
self.running = False self.running = False
self.countdown_time = self.default_time self.countdown_time = self.default_time
self.save() self.save(skip_autoupdate=skip_autoupdate)