Merge pull request #1993 from emanuelschuetze/fix1710

Added motion poll pdf (Fixes #1710).
This commit is contained in:
Norman Jäckel 2016-02-23 22:38:28 +01:00
commit 9a94dfc735
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(Spacer(0, 0.8 * cm))
cell.append(Paragraph(_("Motion No. %s") % poll.motion.identifier, stylesheet['Ballot_title'])) cell.append(Paragraph(_("Motion No. %s") % poll.motion.identifier, stylesheet['Ballot_title']))
cell.append(Paragraph(poll.motion.title, stylesheet['Ballot_subtitle'])) 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(Spacer(0, 0.5 * cm))
cell.append(Paragraph("<font name='circlefont' size='15'>%s</font> <font name='Ubuntu'>%s</font>" cell.append(Paragraph("<font name='circlefont' size='15'>%s</font> <font name='Ubuntu'>%s</font>"
% (circle, _("Yes")), stylesheet['Ballot_option'])) % (circle, _("Yes")), stylesheet['Ballot_option']))
@ -377,7 +376,7 @@ def motion_poll_to_pdf(pdf, poll):
# print ballot papers # print ballot papers
if number > 0: if number > 0:
# TODO: try [cell, cell] * (number / 2) # TODO: try [cell, cell] * (number / 2)
for user in range(number / 2): for user in range(int(number / 2)):
data.append([cell, cell]) data.append([cell, cell])
rest = number % 2 rest = number % 2
if rest: if rest:

View File

@ -131,6 +131,13 @@
title="{{ 'Delete' | translate }}"> title="{{ 'Delete' | translate }}">
<i class="fa fa-times"></i> <i class="fa fa-times"></i>
</button> </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 --> <!-- Poll results -->
<div ng-show="poll.has_votes" class="pollresults"> <div ng-show="poll.has_votes" class="pollresults">
<table class="table"> <table class="table">

View File

@ -10,4 +10,8 @@ urlpatterns = [
url(r'^(?P<pk>\d+)/pdf/$', url(r'^(?P<pk>\d+)/pdf/$',
views.MotionPDFView.as_view(print_all_motions=False), views.MotionPDFView.as_view(print_all_motions=False),
name='motions_single_pdf'), 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.db import transaction
from django.http import Http404 from django.http import Http404
from django.shortcuts import get_object_or_404
from django.utils.text import slugify from django.utils.text import slugify
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.translation import ugettext_noop from django.utils.translation import ugettext_noop
@ -325,7 +324,7 @@ class WorkflowViewSet(ModelViewSet):
# Views to generate PDFs # Views to generate PDFs
class PollPDFView(PDFView): class MotionPollPDF(PDFView):
""" """
Generates a ballotpaper. Generates a ballotpaper.
""" """
@ -333,28 +332,15 @@ class PollPDFView(PDFView):
required_permission = 'motions.can_manage' required_permission = 'motions.can_manage'
top_space = 0 top_space = 0
def get_object(self): def get(self, request, *args, **kwargs):
""" self.poll = MotionPoll.objects.get(pk=self.kwargs['poll_pk'])
Return a MotionPoll object. return super().get(request, *args, **kwargs)
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_filename(self): def get_filename(self):
""" """
Return the filename for the PDF. 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): def get_template(self, buffer):
return SimpleDocTemplate( return SimpleDocTemplate(
@ -368,7 +354,7 @@ class PollPDFView(PDFView):
""" """
Append PDF objects. Append PDF objects.
""" """
motion_poll_to_pdf(pdf, self.get_object()) motion_poll_to_pdf(pdf, self.poll)
class MotionPDFView(SingleObjectMixin, PDFView): class MotionPDFView(SingleObjectMixin, PDFView):