rewrite projector_edit view as class based view

This commit is contained in:
Oskar Hahn 2012-07-01 10:52:08 +02:00
parent 2ba1b7e3bc
commit ea4da31b0c
2 changed files with 45 additions and 29 deletions

View File

@ -17,7 +17,7 @@ from openslides.utils.views import CreateView
from openslides.projector.models import ProjectorSlide
from openslides.projector.views import (ControlView, ActivateView,
CustomSlideCreateView, CustomSlideUpdateView, CustomSlideDeleteView,
CountdownEdit)
CountdownEdit, ProjectorEdit)
@ -63,20 +63,35 @@ urlpatterns = patterns('projector.views',
name='customslide_delete',
),
url(r'^bigger/$', 'projector_edit', {'direction': 'bigger'},
name='projector_bigger'),
url(r'^bigger/$',
ProjectorEdit.as_view(),
{'direction': 'bigger'},
name='projector_bigger',
),
url(r'^smaller/$', 'projector_edit', {'direction': 'smaller'},
name='projector_smaller'),
url(r'^smaller/$',
ProjectorEdit.as_view(),
{'direction': 'smaller'},
name='projector_smaller',
),
url(r'^up/$', 'projector_edit', {'direction': 'up'},
name='projector_up'),
url(r'^up/$',
ProjectorEdit.as_view(),
{'direction': 'up'},
name='projector_up',
),
url(r'^down/$', 'projector_edit', {'direction': 'down'},
name='projector_down'),
url(r'^down/$',
ProjectorEdit.as_view(),
{'direction': 'down'},
name='projector_down',
),
url(r'^clean/$', 'projector_edit', {'direction': 'clean'},
name='projector_clean'),
url(r'^clean/$',
ProjectorEdit.as_view(),
{'direction': 'clean'},
name='projector_clean',
),
# TODO: Merge the following lines with this one:
## url(r'^countdown/(?P<command>[^/]*)/$',

View File

@ -209,8 +209,13 @@ def active_slide(request, sid=None):
)
@permission_required('agenda.can_manage_agenda')
def projector_edit(request, direction):
class ProjectorEdit(RedirectView):
permission_required = 'projector.can_manage_projector'
url = 'projector_control'
allow_ajax = True
def pre_redirect(self, request, *args, **kwargs):
direction = kwargs['direction']
if direction == 'bigger':
config['bigger'] = int(config['bigger']) + 20
elif direction == 'smaller':
@ -224,10 +229,6 @@ def projector_edit(request, direction):
config['up'] = 0
config['bigger'] = 100
if request.is_ajax():
return ajax_request({})
return redirect(reverse('projector_control'))
class CountdownEdit(RedirectView):
permission_required = 'projector.can_manage_projector'
@ -235,7 +236,7 @@ class CountdownEdit(RedirectView):
allow_ajax = True
def pre_redirect(self, request, *args, **kwargs):
self.command = command = self.kwargs['command']
command = kwargs['command']
if command in ['reset', 'start', 'stop']:
config['countdown_time'] = config['countdown_time']