From ea4da31b0c709290d14cc3884e85ce76c8054175 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sun, 1 Jul 2012 10:52:08 +0200 Subject: [PATCH] rewrite projector_edit view as class based view --- openslides/projector/urls.py | 37 ++++++++++++++++++++++++----------- openslides/projector/views.py | 37 ++++++++++++++++++----------------- 2 files changed, 45 insertions(+), 29 deletions(-) diff --git a/openslides/projector/urls.py b/openslides/projector/urls.py index 5a55e35ab..36a5179d2 100644 --- a/openslides/projector/urls.py +++ b/openslides/projector/urls.py @@ -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[^/]*)/$', diff --git a/openslides/projector/views.py b/openslides/projector/views.py index 24865ba43..c1a582cc9 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -209,24 +209,25 @@ def active_slide(request, sid=None): ) -@permission_required('agenda.can_manage_agenda') -def projector_edit(request, direction): - if direction == 'bigger': - config['bigger'] = int(config['bigger']) + 20 - elif direction == 'smaller': - config['bigger'] = int(config['bigger']) - 20 - elif direction == 'up': - config['up'] = int(config['up']) - 10 - elif direction == 'down': - if config['up'] < 0: - config['up'] = int(config['up']) + 10 - elif direction == 'clean': - config['up'] = 0 - config['bigger'] = 100 +class ProjectorEdit(RedirectView): + permission_required = 'projector.can_manage_projector' + url = 'projector_control' + allow_ajax = True - if request.is_ajax(): - return ajax_request({}) - return redirect(reverse('projector_control')) + def pre_redirect(self, request, *args, **kwargs): + direction = kwargs['direction'] + if direction == 'bigger': + config['bigger'] = int(config['bigger']) + 20 + elif direction == 'smaller': + config['bigger'] = int(config['bigger']) - 20 + elif direction == 'up': + config['up'] = int(config['up']) - 10 + elif direction == 'down': + if config['up'] < 0: + config['up'] = int(config['up']) + 10 + elif direction == 'clean': + config['up'] = 0 + config['bigger'] = 100 class CountdownEdit(RedirectView): @@ -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']