#94 Countdown: support for pause/resume / #95 Countdown: show correct time format as mm:ss

This commit is contained in:
René Köcher 2012-04-25 17:17:24 +02:00
parent 3cb7417028
commit 07b5614fac
4 changed files with 43 additions and 9 deletions

View File

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

View File

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

View File

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

View File

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