From eebb621a98930ea085e47ed1188502c045883f30 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Tue, 23 Feb 2016 22:05:15 +0100 Subject: [PATCH] Added motion poll pdf (Fixes #1710). --- openslides/motions/pdf.py | 3 +-- .../templates/motions/motion-detail.html | 7 +++++ openslides/motions/urls.py | 4 +++ openslides/motions/views.py | 26 +++++-------------- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/openslides/motions/pdf.py b/openslides/motions/pdf.py index 5626ff195..bf15915bd 100644 --- a/openslides/motions/pdf.py +++ b/openslides/motions/pdf.py @@ -344,7 +344,6 @@ def motion_poll_to_pdf(pdf, poll): cell.append(Spacer(0, 0.8 * cm)) cell.append(Paragraph(_("Motion No. %s") % poll.motion.identifier, stylesheet['Ballot_title'])) cell.append(Paragraph(poll.motion.title, stylesheet['Ballot_subtitle'])) - cell.append(Paragraph(_("%d. Vote") % poll.poll_number, stylesheet['Ballot_description'])) cell.append(Spacer(0, 0.5 * cm)) cell.append(Paragraph("%s %s" % (circle, _("Yes")), stylesheet['Ballot_option'])) @@ -377,7 +376,7 @@ def motion_poll_to_pdf(pdf, poll): # print ballot papers if number > 0: # TODO: try [cell, cell] * (number / 2) - for user in range(number / 2): + for user in range(int(number / 2)): data.append([cell, cell]) rest = number % 2 if rest: diff --git a/openslides/motions/static/templates/motions/motion-detail.html b/openslides/motions/static/templates/motions/motion-detail.html index 648579fc3..6880b47eb 100644 --- a/openslides/motions/static/templates/motions/motion-detail.html +++ b/openslides/motions/static/templates/motions/motion-detail.html @@ -131,6 +131,13 @@ title="{{ 'Delete' | translate }}"> + + + + +
diff --git a/openslides/motions/urls.py b/openslides/motions/urls.py index c707d67c2..9b37d60d8 100644 --- a/openslides/motions/urls.py +++ b/openslides/motions/urls.py @@ -10,4 +10,8 @@ urlpatterns = [ url(r'^(?P\d+)/pdf/$', views.MotionPDFView.as_view(print_all_motions=False), name='motions_single_pdf'), + + url(r'^poll/(?P\d+)/print/$', + views.MotionPollPDF.as_view(), + name='motionpoll_pdf'), ] diff --git a/openslides/motions/views.py b/openslides/motions/views.py index 27d582982..8af5de929 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -1,6 +1,5 @@ from django.db import transaction from django.http import Http404 -from django.shortcuts import get_object_or_404 from django.utils.text import slugify from django.utils.translation import ugettext as _ from django.utils.translation import ugettext_noop @@ -325,7 +324,7 @@ class WorkflowViewSet(ModelViewSet): # Views to generate PDFs -class PollPDFView(PDFView): +class MotionPollPDF(PDFView): """ Generates a ballotpaper. """ @@ -333,28 +332,15 @@ class PollPDFView(PDFView): required_permission = 'motions.can_manage' top_space = 0 - def get_object(self): - """ - Return a MotionPoll object. - - Use the motion id and the poll_number from the url kwargs to get the - object. - """ - try: - obj = self._object - except AttributeError: - queryset = MotionPoll.objects.filter( - motion=self.kwargs['pk'], - poll_number=self.kwargs['poll_number']) - obj = get_object_or_404(queryset) - self._object = obj - return obj + def get(self, request, *args, **kwargs): + self.poll = MotionPoll.objects.get(pk=self.kwargs['poll_pk']) + return super().get(request, *args, **kwargs) def get_filename(self): """ Return the filename for the PDF. """ - return u'%s%s_%s' % (_("Motion"), str(self.get_object().poll_number), _("Vote")) + return u'%s_%s' % (_("Motion"), _("Vote")) def get_template(self, buffer): return SimpleDocTemplate( @@ -368,7 +354,7 @@ class PollPDFView(PDFView): """ Append PDF objects. """ - motion_poll_to_pdf(pdf, self.get_object()) + motion_poll_to_pdf(pdf, self.poll) class MotionPDFView(SingleObjectMixin, PDFView):