Passed
Push — master ( b124da...78fa88 )
by Jordi
04:16
created

DownloadView.__call__()   A

Complexity

Conditions 1

Size

Total Lines 5
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 5
rs 10
c 0
b 0
f 0
cc 1
nop 1
1
# -*- coding: utf-8 -*-
2
#
3
# This file is part of SENAITE.CORE
4
#
5
# Copyright 2018 by it's authors.
6
7
from Products.Five.browser import BrowserView
8
9
10
class DownloadView(BrowserView):
11
    """Download View
12
    """
13
14
    def __init__(self, context, request):
15
        super(DownloadView, self).__init__(context, request)
16
17
    def __call__(self):
18
        ar = self.context.getAnalysisRequest()
19
        filename = "{}.pdf".format(ar.getId())
20
        pdf = self.context.getPdf()
21
        self.download(pdf.data, filename)
22
23
    def download(self, data, filename, content_type="application/pdf"):
24
        """Download the PDF
25
        """
26
        self.request.response.setHeader(
27
            "Content-Disposition", "inline; filename=%s" % filename)
28
        self.request.response.setHeader("Content-Type", content_type)
29
        self.request.response.setHeader("Content-Length", len(data))
30
        self.request.response.setHeader("Cache-Control", "no-store")
31
        self.request.response.setHeader("Pragma", "no-cache")
32
        self.request.response.write(data)
33