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 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',
@ -76,21 +78,47 @@ urlpatterns = patterns('projector.views',
url(r'^clean/$', 'projector_edit', {'direction': 'clean'},
name='projector_clean'),
url(r'^countdown/show/$', 'projector_countdown', {'command': 'show'},
name='countdown_open'),
# TODO: Merge the following lines with this one:
## 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'},
name='countdown_start'),
url(r'^countdown/show/$',
CountdownEdit.as_view(),
{'command': 'show'},
name='countdown_open',
),
url(r'^countdown/stop/$', 'projector_countdown', {'command': 'stop'},
name='countdown_stop'),
url(r'^countdown/hide/$',
CountdownEdit.as_view(),
{'command': 'hide'},
name='countdown_close',
),
url(r'^countdown/set-default/$', 'projector_countdown', {'command': 'set_default'},
name='countdown_set_default'),
url(r'^countdown/reset/$',
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({
'countdown_time': config['agenda_countdown_time'],
'countdown_time': config['countdown_time'],
'countdown_state' : config['countdown_state'],
'overlays': self.get_projector_overlays(),
'widgets': widgets,
@ -229,55 +229,44 @@ def projector_edit(request, direction):
return redirect(reverse('projector_control'))
@permission_required('projector.can_manage_projector')
def projector_countdown(request, command):
#todo: why is there the time argument?
if command in ['reset','start','stop']:
config['countdown_time'] = config['agenda_countdown_time']
class CountdownEdit(RedirectView):
permission_required = 'projector.can_manage_projector'
url = 'projector_control'
allow_ajax = True
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':
config['countdown_start_stamp'] = time()
config['countdown_pause_stamp'] = 0
config['countdown_state'] = 'inactive'
elif command == 'start':
elif command == 'start':
# 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()
start_stamp = config['countdown_start_stamp']
pause_stamp = config['countdown_pause_stamp']
now = time()
config['countdown_start_stamp'] = n - (p - s)
config['countdown_start_stamp'] = now - (pause_stamp - start_stamp)
else:
config['countdown_start_stamp'] = time()
config['countdown_state'] = 'active'
config['countdown_pause_stamp'] = 0
elif command == 'stop':
if config['countdown_state'] == 'active':
config['countdown_pause_stamp'] = time()
config['countdown_state'] = 'paused'
elif command == 'set_default':
try:
config['agenda_countdown_time'] = int(request.GET['countdown_time'])
except ValueError:
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'))
elif command == 'stop':
if config['countdown_state'] == 'active':
config['countdown_pause_stamp'] = time()
config['countdown_state'] = 'paused'
elif command == 'set-default':
try:
config['countdown_time'] = int(self.request.GET['countdown_time'])
except ValueError:
pass
except AttributeError:
pass
def register_tab(request):