rewrote countdown view as class based view

This commit is contained in:
Oskar Hahn 2012-07-01 10:44:41 +02:00
parent 0a269ce601
commit 2ba1b7e3bc
2 changed files with 70 additions and 53 deletions

View File

@ -12,11 +12,13 @@
from django.conf.urls.defaults import * from django.conf.urls.defaults import *
from utils.views import CreateView from openslides.utils.views import CreateView
from openslides.projector.models import ProjectorSlide
from openslides.projector.views import (ControlView, ActivateView,
CustomSlideCreateView, CustomSlideUpdateView, CustomSlideDeleteView,
CountdownEdit)
from views import ControlView, ActivateView, CustomSlideCreateView, CustomSlideUpdateView, CustomSlideDeleteView
from agenda.views import ItemUpdate
from models import ProjectorSlide
urlpatterns = patterns('projector.views', urlpatterns = patterns('projector.views',
@ -76,21 +78,47 @@ urlpatterns = patterns('projector.views',
url(r'^clean/$', 'projector_edit', {'direction': 'clean'}, url(r'^clean/$', 'projector_edit', {'direction': 'clean'},
name='projector_clean'), name='projector_clean'),
url(r'^countdown/show/$', 'projector_countdown', {'command': 'show'}, # TODO: Merge the following lines with this one:
name='countdown_open'), ## url(r'^countdown/(?P<command>[^/]*)/$',
## CountdownEdit.as_view(),
## name='countdown_edit',
## ),
url(r'^countdown/hide/$', 'projector_countdown', {'command': 'hide'},
name='countdown_close'),
url(r'^countdown/reset/$', 'projector_countdown', {'command': 'reset'},
name='countdown_reset'),
url(r'^countdown/start/$', 'projector_countdown', {'command': 'start'}, url(r'^countdown/show/$',
name='countdown_start'), CountdownEdit.as_view(),
{'command': 'show'},
name='countdown_open',
),
url(r'^countdown/stop/$', 'projector_countdown', {'command': 'stop'}, url(r'^countdown/hide/$',
name='countdown_stop'), CountdownEdit.as_view(),
{'command': 'hide'},
name='countdown_close',
),
url(r'^countdown/set-default/$', 'projector_countdown', {'command': 'set_default'}, url(r'^countdown/reset/$',
name='countdown_set_default'), CountdownEdit.as_view(),
{'command': 'reset'},
name='countdown_reset',
),
url(r'^countdown/start/$',
CountdownEdit.as_view(),
{'command': 'start'},
name='countdown_start',
),
url(r'^countdown/stop/$',
CountdownEdit.as_view(),
{'command': 'stop'},
name='countdown_stop',
),
url(r'^countdown/set-default/$',
CountdownEdit.as_view(),
{'command': 'set-default'},
name='countdown_set_default',
),
) )

View File

@ -91,7 +91,7 @@ class ControlView(TemplateView):
context.update({ context.update({
'countdown_time': config['agenda_countdown_time'], 'countdown_time': config['countdown_time'],
'countdown_state' : config['countdown_state'], 'countdown_state' : config['countdown_state'],
'overlays': self.get_projector_overlays(), 'overlays': self.get_projector_overlays(),
'widgets': widgets, 'widgets': widgets,
@ -229,55 +229,44 @@ def projector_edit(request, direction):
return redirect(reverse('projector_control')) return redirect(reverse('projector_control'))
@permission_required('projector.can_manage_projector') class CountdownEdit(RedirectView):
def projector_countdown(request, command): permission_required = 'projector.can_manage_projector'
#todo: why is there the time argument? url = 'projector_control'
if command in ['reset','start','stop']: allow_ajax = True
config['countdown_time'] = config['agenda_countdown_time']
def pre_redirect(self, request, *args, **kwargs):
self.command = command = self.kwargs['command']
if command in ['reset', 'start', 'stop']:
config['countdown_time'] = config['countdown_time']
if command =='reset':
if command == 'reset': if command == 'reset':
config['countdown_start_stamp'] = time() config['countdown_start_stamp'] = time()
config['countdown_pause_stamp'] = 0 config['countdown_pause_stamp'] = 0
config['countdown_state'] = 'inactive' config['countdown_state'] = 'inactive'
elif command == 'start':
elif command == 'start':
# if we had stopped the countdown resume were we left of # if we had stopped the countdown resume were we left of
if config['countdown_state'] == 'paused': if config['countdown_state'] == 'paused':
s = config['countdown_start_stamp'] start_stamp = config['countdown_start_stamp']
p = config['countdown_pause_stamp'] pause_stamp = config['countdown_pause_stamp']
n = time() now = time()
config['countdown_start_stamp'] = n - (p - s) config['countdown_start_stamp'] = now - (pause_stamp - start_stamp)
else: else:
config['countdown_start_stamp'] = time() config['countdown_start_stamp'] = time()
config['countdown_state'] = 'active' config['countdown_state'] = 'active'
config['countdown_pause_stamp'] = 0 config['countdown_pause_stamp'] = 0
elif command == 'stop':
elif command == 'stop': if config['countdown_state'] == 'active':
if config['countdown_state'] == 'active': config['countdown_pause_stamp'] = time()
config['countdown_pause_stamp'] = time() config['countdown_state'] = 'paused'
config['countdown_state'] = 'paused' elif command == 'set-default':
try:
elif command == 'set_default': config['countdown_time'] = int(self.request.GET['countdown_time'])
try: except ValueError:
config['agenda_countdown_time'] = int(request.GET['countdown_time']) pass
except AttributeError:
except ValueError: pass
pass
except AttributeError:
pass
if request.is_ajax():
if command == "show":
link = reverse('countdown_close')
else:
link = reverse('countdown_open')
return ajax_request({'countdown_visible': config['countdown_visible'],
'link': link})
return redirect(reverse('projector_control'))
def register_tab(request): def register_tab(request):