From 07b5614fac770061399a26d2fac5066403efee14 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rene=CC=81=20Ko=CC=88cher?= Date: Wed, 25 Apr 2012 17:17:24 +0200 Subject: [PATCH] #94 Countdown: support for pause/resume / #95 Countdown: show correct time format as mm:ss --- openslides/config/models.py | 2 ++ openslides/projector/models.py | 4 +++- openslides/projector/projector.py | 17 +++++++++++++---- openslides/projector/views.py | 29 +++++++++++++++++++++++++---- 4 files changed, 43 insertions(+), 9 deletions(-) diff --git a/openslides/config/models.py b/openslides/config/models.py index bd2d046d1..4790b9e43 100644 --- a/openslides/config/models.py +++ b/openslides/config/models.py @@ -58,6 +58,8 @@ class Config(object): for receiver, value in default_config_value.send(sender='config', key=key): if value is not None: +# if settings.DEBUG: +# print 'Using default for %s' % key return value if settings.DEBUG: print "No default value for: %s" % key diff --git a/openslides/projector/models.py b/openslides/projector/models.py index 3836c60c0..8b11e0493 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -54,7 +54,9 @@ def default_config(sender, key, **kwargs): return { 'projector_message': '', 'countdown_time': 60, - 'countdown_start': False, + 'countdown_start_stamp': 0, + 'countdown_pause_stamp': 0, + 'countdown_state': 'inactive', 'bigger': 100, 'up': 0, }.get(key) diff --git a/openslides/projector/projector.py b/openslides/projector/projector.py index 62de5a58f..d943803af 100644 --- a/openslides/projector/projector.py +++ b/openslides/projector/projector.py @@ -86,10 +86,19 @@ def countdown(sender, **kwargs): if kwargs['register']: return name if name in kwargs['call']: - if config['countdown_start'] is False: - config['countdown_start'] = time() - seconds = max(0, int(config['countdown_start'] + config['countdown_time'] - time())) - return (name, seconds) + if config['countdown_state'] == 'active': + seconds = max(0, int(config['countdown_start_stamp'] + config['countdown_time'] - time())) + elif config['countdown_state'] == 'paused': + seconds = max(0, int(config['countdown_start_stamp'] + config['countdown_time'] - config['countdown_pause_stamp'])) + elif config['countdown_state'] == 'inactive': + seconds = max(0, int(config['countdown_time'])) + else: + seconds = 0 + + if seconds == 0: + config['countdown_state'] = 'expired' + + return (name, '%02d:%02d' % (seconds / 60, seconds % 60)) return None diff --git a/openslides/projector/views.py b/openslides/projector/views.py index 1aa67cad3..dc81bc2f8 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -191,12 +191,33 @@ def projector_edit(request, direction): @permission_required('projector.can_manage_projector') def projector_countdown(request, command): #todo: why is there the time argument? - if command == 'reset': - config['countdown_start'] = time() + if command in ['reset','start','stop']: + config['countdown_time'] = config['agenda_countdown_time'] + + if command =='reset': + if command == 'reset': + config['countdown_start_stamp'] = time() + config['countdown_pause_stamp'] = 0 + config['countdown_state'] = 'inactive' + elif command == 'start': - config['countdown_run'] = True + # if we had stopped the countdown resume were we left of + if config['countdown_state'] == 'paused': + s = config['countdown_start_stamp'] + p = config['countdown_pause_stamp'] + n = time() + + config['countdown_start_stamp'] = n - (p - s) + else: + config['countdown_start_stamp'] = time() + + config['countdown_state'] = 'active' + config['countdown_pause_stamp'] = 0 + elif command == 'stop': - config['countdown_run'] = False + if config['countdown_state'] == 'active': + config['countdown_pause_stamp'] = time() + config['countdown_state'] = 'paused' if request.is_ajax(): if command == "show":