2011-07-31 10:46:29 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
2012-10-24 11:04:23 +02:00
|
|
|
openslides.motion.views
|
2013-01-06 12:07:37 +01:00
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2012-10-24 11:04:23 +02:00
|
|
|
Views for the motion app.
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
:copyright: 2011, 2012 by the OpenSlides team, see AUTHORS.
|
2011-07-31 10:46:29 +02:00
|
|
|
:license: GNU GPL, see LICENSE for more details.
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
from reportlab.platypus import Paragraph
|
2012-07-08 09:21:39 +02:00
|
|
|
|
|
|
|
from django.core.urlresolvers import reverse
|
2013-01-06 12:07:37 +01:00
|
|
|
from django.contrib import messages
|
2011-11-09 22:53:10 +01:00
|
|
|
from django.db import transaction
|
2013-01-06 12:07:37 +01:00
|
|
|
from django.db.models import Model
|
|
|
|
from django.utils.translation import ugettext as _, ugettext_lazy
|
|
|
|
from django.views.generic.detail import SingleObjectMixin
|
2013-01-26 15:25:54 +01:00
|
|
|
from django.http import Http404
|
2012-06-11 13:43:48 +02:00
|
|
|
|
2012-07-01 15:35:05 +02:00
|
|
|
from openslides.utils.pdf import stylesheet
|
2012-11-24 14:01:21 +01:00
|
|
|
from openslides.utils.views import (
|
2013-01-06 12:07:37 +01:00
|
|
|
TemplateView, RedirectView, UpdateView, CreateView, DeleteView, PDFView,
|
|
|
|
DetailView, ListView)
|
|
|
|
from openslides.utils.template import Tab
|
|
|
|
from openslides.utils.utils import html_strong
|
|
|
|
from openslides.projector.api import get_active_slide
|
|
|
|
from openslides.projector.projector import Widget, SLIDE
|
2013-01-26 15:25:54 +01:00
|
|
|
from openslides.config.models import config
|
|
|
|
from .models import Motion, MotionSubmitter
|
|
|
|
from .forms import (BaseMotionForm, MotionSubmitterMixin, MotionSupporterMixin,
|
|
|
|
MotionTrivialChangesMixin)
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
class MotionListView(ListView):
|
2013-01-26 12:28:51 +01:00
|
|
|
"""
|
|
|
|
List all motion.
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
permission_required = 'motion.can_see_motion'
|
2012-10-25 09:23:24 +02:00
|
|
|
model = Motion
|
2012-10-28 02:09:47 +02:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
motion_list = MotionListView.as_view()
|
2012-10-28 19:59:41 +01:00
|
|
|
|
2011-07-31 10:46:29 +02:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
class MotionDetailView(DetailView):
|
2013-01-26 12:28:51 +01:00
|
|
|
"""
|
|
|
|
Show the details of one motion.
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
permission_required = 'motion.can_see_motion'
|
2012-10-24 11:04:23 +02:00
|
|
|
model = Motion
|
2013-01-06 12:07:37 +01:00
|
|
|
template_name = 'motion/motion_detail.html'
|
2012-04-27 21:22:44 +02:00
|
|
|
|
|
|
|
def get_object(self):
|
2013-01-06 12:07:37 +01:00
|
|
|
object = super(MotionDetailView, self).get_object()
|
|
|
|
version_id = self.kwargs.get('version_id', None)
|
|
|
|
if version_id is not None:
|
2013-01-26 15:25:54 +01:00
|
|
|
try:
|
|
|
|
object.version = int(version_id) -1
|
|
|
|
except IndexError:
|
|
|
|
raise Http404
|
2013-01-06 12:07:37 +01:00
|
|
|
return object
|
2012-04-27 21:22:44 +02:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
motion_detail = MotionDetailView.as_view()
|
2012-04-27 21:22:44 +02:00
|
|
|
|
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
class MotionMixin(object):
|
2013-01-26 12:28:51 +01:00
|
|
|
"""
|
|
|
|
Mixin to add save the version-data to the motion-object
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
def manipulate_object(self, form):
|
2013-01-26 15:25:54 +01:00
|
|
|
super(MotionMixin, self).manipulate_object(form)
|
2013-01-06 12:07:37 +01:00
|
|
|
for attr in ['title', 'text', 'reason']:
|
|
|
|
setattr(self.object, attr, form.cleaned_data[attr])
|
2012-07-13 11:16:06 +02:00
|
|
|
|
2013-01-26 15:25:54 +01:00
|
|
|
def post_save(self, form):
|
|
|
|
super(MotionMixin, self).post_save(form)
|
|
|
|
# TODO: only delete and save neccessary submitters
|
|
|
|
self.object.submitter.all().delete()
|
|
|
|
MotionSubmitter.objects.bulk_create(
|
|
|
|
[MotionSubmitter(motion=self.object, person=person)
|
|
|
|
for person in form.cleaned_data['submitter']])
|
|
|
|
|
|
|
|
def get_form_class(self):
|
|
|
|
form_classes = [BaseMotionForm]
|
|
|
|
if config['motion_allow_trivial_change']:
|
|
|
|
form_classes.append(MotionTrivialChangesMixin)
|
|
|
|
if self.request.user.has_perm('motion.can_manage_motion'):
|
|
|
|
form_classes.append(MotionSubmitterMixin)
|
|
|
|
if config['motion_min_supporters'] > 0:
|
|
|
|
form_classes.append(MotionSupporterMixin)
|
|
|
|
return type('MotionForm', tuple(form_classes), {})
|
|
|
|
|
2012-02-14 16:31:21 +01:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
class MotionCreateView(MotionMixin, CreateView):
|
2013-01-26 12:28:51 +01:00
|
|
|
"""
|
|
|
|
Create a motion.
|
|
|
|
"""
|
2013-01-06 12:07:37 +01:00
|
|
|
permission_required = 'motion.can_create_motion'
|
|
|
|
model = Motion
|
2012-03-18 17:11:58 +01:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
motion_create = MotionCreateView.as_view()
|
2012-03-18 17:11:58 +01:00
|
|
|
|
2012-06-11 13:43:48 +02:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
class MotionUpdateView(MotionMixin, UpdateView):
|
2013-01-26 12:28:51 +01:00
|
|
|
"""
|
|
|
|
Update a motion.
|
|
|
|
"""
|
2013-01-26 15:25:54 +01:00
|
|
|
# TODO: set permissions
|
2013-01-06 12:07:37 +01:00
|
|
|
model = Motion
|
2012-06-11 13:43:48 +02:00
|
|
|
|
2013-01-06 12:07:37 +01:00
|
|
|
motion_edit = MotionUpdateView.as_view()
|
2013-01-26 15:25:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
def register_tab(request):
|
|
|
|
"""
|
|
|
|
Register the projector tab.
|
|
|
|
"""
|
|
|
|
selected = request.path.startswith('/motion/')
|
|
|
|
return Tab(
|
|
|
|
title=_('Motions'),
|
|
|
|
url=reverse('motion_list'),
|
|
|
|
permission=request.user.has_perm('motion.can_see_motion'),
|
|
|
|
selected=selected,
|
|
|
|
)
|