From 90787b259741ad134539fd6b9ed00ec7a0268752 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Fri, 18 May 2012 23:07:09 +0200 Subject: [PATCH] #89: Edit custom slides. --- openslides/projector/models.py | 4 +-- .../templates/projector/control.html | 4 +-- .../projector/templates/projector/new.html | 9 +++--- openslides/projector/urls.py | 15 ++++----- openslides/projector/views.py | 32 +++++++++++++++++-- 5 files changed, 45 insertions(+), 19 deletions(-) diff --git a/openslides/projector/models.py b/openslides/projector/models.py index 8a4949b1a..c9bf3725e 100644 --- a/openslides/projector/models.py +++ b/openslides/projector/models.py @@ -25,7 +25,7 @@ from utils.translation_ext import ugettext as _ class ProjectorSlide(models.Model, SlideMixin): prefix = 'ProjectorSlide' - title = models.CharField(max_length=100, verbose_name=_("Title")) + title = models.CharField(max_length=256, verbose_name=_("Title")) text = models.TextField(null=True, blank=True, verbose_name=_("Text")) #weight = models.IntegerField(default=0, verbose_name=_("Weight")) @@ -57,7 +57,7 @@ class ProjectorOverlay(models.Model): return self.def_name -register_slidemodel(ProjectorSlide, model_name='customslide') +register_slidemodel(ProjectorSlide, control_template='projector/control_customslide.html') @receiver(default_config_value, dispatch_uid="projector_default_config") diff --git a/openslides/projector/templates/projector/control.html b/openslides/projector/templates/projector/control.html index bdad2ed49..a4889ce2a 100644 --- a/openslides/projector/templates/projector/control.html +++ b/openslides/projector/templates/projector/control.html @@ -259,8 +259,8 @@
{% endif %} {% endfor %} - - diff --git a/openslides/projector/templates/projector/new.html b/openslides/projector/templates/projector/new.html index 927839d2c..f93fa653b 100644 --- a/openslides/projector/templates/projector/new.html +++ b/openslides/projector/templates/projector/new.html @@ -3,10 +3,10 @@ {% load tags %} {% load i18n %} -{% block title %}{{ block.super }} – {%trans "New custom slide" %}{% endblock %} +{% block title %}{{ block.super }} – {%trans "Custom slide" %}{% endblock %} {% block content %} -

{% trans 'New custom slide' %}

+

{% trans 'Custom slide' %}

{% csrf_token %} {{ form.as_p }} - -
- {% endblock %} diff --git a/openslides/projector/urls.py b/openslides/projector/urls.py index 3ea30144a..3385ffcc6 100644 --- a/openslides/projector/urls.py +++ b/openslides/projector/urls.py @@ -14,7 +14,7 @@ from django.conf.urls.defaults import * from utils.views import CreateView -from views import ControlView, ActivateView +from views import ControlView, ActivateView, CustomSlideCreateView, CustomSlideUpdateView from agenda.views import ItemUpdate from models import ProjectorSlide @@ -47,13 +47,12 @@ urlpatterns = patterns('projector.views', ), url(r'^new/$', - CreateView.as_view( - success_url='projector_control', - model=ProjectorSlide, - template_name='projector/new.html', - permission_required='projector.can_manage_projector' - ), - name='custom_slides_new', + CustomSlideCreateView.as_view(), + name='customslide_new', + ), + url(r'^(?P\d+)/edit/$', + CustomSlideUpdateView.as_view(), + name='customslide_edit', ), url(r'^bigger/$', 'projector_edit', {'direction': 'bigger'}, diff --git a/openslides/projector/views.py b/openslides/projector/views.py index 6cde356c8..f008c32a6 100644 --- a/openslides/projector/views.py +++ b/openslides/projector/views.py @@ -13,6 +13,7 @@ from datetime import datetime from time import time +from django.contrib import messages from django.shortcuts import render_to_response, redirect from django.template import RequestContext from django.core.urlresolvers import reverse @@ -23,7 +24,7 @@ from django.template.loader import render_to_string from django.db.models import Q -from utils.views import TemplateView, RedirectView +from utils.views import TemplateView, RedirectView, CreateView, UpdateView from utils.utils import template, permission_required, \ del_confirm_form, ajax_request from utils.template import render_block_to_string @@ -33,7 +34,7 @@ from config.models import config from api import get_active_slide, set_active_slide, projector_message_set, projector_message_delete, get_slide_from_sid from projector import SLIDE -from models import ProjectorOverlay +from models import ProjectorOverlay, ProjectorSlide from openslides.projector.signals import projector_overlays, projector_control_box from openslides.utils.signals import template_manipulation @@ -114,6 +115,33 @@ class ActivateView(RedirectView): config['bigger'] = 100 return context +class CustomSlideCreateView(CreateView): + permission_required = 'agenda.can_manage_agenda' + template_name = 'projector/new.html' + model = ProjectorSlide + context_object_name = 'customslide' + success_url = 'projector_control' + apply_url = 'customslide_edit' + + def get_success_url(self): + messages.success(self.request, _("Custom slide %s was successfully created.") % self.request.POST['title']) + if 'apply' in self.request.POST: + return reverse(self.get_apply_url(), args=[self.object.id]) + return reverse(super(CreateView, self).get_success_url()) + +class CustomSlideUpdateView(UpdateView): + permission_required = 'projector.can_manage_projector' + template_name = 'projector/new.html' + model = ProjectorSlide + context_object_name = 'customslide' + success_url = 'projector_control' + apply_url = 'customslide_edit' + + def get_success_url(self): + messages.success(self.request, _("Custom slide %s was successfully modified.") % self.request.POST['title']) + if 'apply' in self.request.POST: + return '' + return reverse(super(UpdateView, self).get_success_url()) @permission_required('projector.can_see_projector') def active_slide(request, sid=None):