From 3812b5ebd1023884fe577f26724d7e2eaeaf9379 Mon Sep 17 00:00:00 2001 From: Emanuel Schuetze Date: Wed, 18 Apr 2012 18:54:48 +0200 Subject: [PATCH] #103: Set application filename. --- openslides/application/urls.py | 1 + openslides/application/views.py | 25 ++++++++++++++----------- openslides/utils/views.py | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/openslides/application/urls.py b/openslides/application/urls.py index dab384289..e49eddd59 100644 --- a/openslides/application/urls.py +++ b/openslides/application/urls.py @@ -109,6 +109,7 @@ urlpatterns = patterns('application.views', url(r'^print/$', ApplicationPDF.as_view(), + {'application_id': None}, name='print_applications', ), diff --git a/openslides/application/views.py b/openslides/application/views.py index 9d6b9e1c3..a9e317878 100644 --- a/openslides/application/views.py +++ b/openslides/application/views.py @@ -593,15 +593,23 @@ def application_import(request): class ApplicationPDF(PDFView): permission_required = 'application.can_manage_application' - filename = u'filename=%s.pdf;' % _("Applications") top_space = 0 - def append_to_pdf(self, story): - try: - application_id = self.kwargs['application_id'] - except KeyError: - application_id = None + def get_filename(self): + application_id = self.kwargs['application_id'] + if application_id is None: + filename = _("Applications") + else: + application = Application.objects.get(id=application_id) + if application.number: + number = application.number + else: + number = "" + filename = u'%s%s' % (_("Application"), str(number)) + return filename + def append_to_pdf(self, story): + application_id = self.kwargs['application_id'] if application_id is None: #print all applications title = config["application_pdf_title"] story.append(Paragraph(title, stylesheet['Heading1'])) @@ -621,11 +629,6 @@ class ApplicationPDF(PDFView): story = self.get_application(application, story) else: # print selected application application = Application.objects.get(id=application_id) - if application.number: - number = application.number - else: - number = "" - filename = u'filename=%s%s.pdf;' % (_("Application"), str(number)) story = self.get_application(application, story) def get_application(self, application, story): diff --git a/openslides/utils/views.py b/openslides/utils/views.py index 69ec0ef3f..81c502268 100644 --- a/openslides/utils/views.py +++ b/openslides/utils/views.py @@ -232,7 +232,7 @@ class PDFView(PermissionMixin, View): def render_to_response(self, filename): response = HttpResponse(mimetype='application/pdf') - filename = u'filename=%s.pdf;' % filename + filename = u'filename=%s.pdf;' % self.get_filename() response['Content-Disposition'] = filename.encode('utf-8') buffer = StringIO()