Added motion poll pdf (Fixes #1710).

This commit is contained in:
Emanuel Schuetze 2016-02-23 22:05:15 +01:00
parent 4016c1ea4b
commit eebb621a98
4 changed files with 18 additions and 22 deletions

View File

@ -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("<font name='circlefont' size='15'>%s</font> <font name='Ubuntu'>%s</font>"
% (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:

View File

@ -131,6 +131,13 @@
title="{{ 'Delete' | translate }}">
<i class="fa fa-times"></i>
</button>
<!-- print poll PDF -->
<a ui-sref="motionpoll_pdf({poll_pk: poll.id})" target="_blank"
class="btn btn-default btn-xs"
title="{{ 'Print ballot paper' | translate }}">
<i class="fa fa-file-pdf-o"></i>
</a>
<!-- Poll results -->
<div ng-show="poll.has_votes" class="pollresults">
<table class="table">

View File

@ -10,4 +10,8 @@ urlpatterns = [
url(r'^(?P<pk>\d+)/pdf/$',
views.MotionPDFView.as_view(print_all_motions=False),
name='motions_single_pdf'),
url(r'^poll/(?P<poll_pk>\d+)/print/$',
views.MotionPollPDF.as_view(),
name='motionpoll_pdf'),
]

View File

@ -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):