2016-01-01 16:13:59 +00:00
|
|
|
from django.http import HttpResponse
|
|
|
|
|
from django.template.defaultfilters import slugify
|
|
|
|
|
from django.views.generic.detail import DetailView
|
|
|
|
|
|
2016-01-14 19:47:57 +00:00
|
|
|
from paperless.db import GnuPG
|
|
|
|
|
|
2016-01-01 16:13:59 +00:00
|
|
|
from .models import Document
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class PdfView(DetailView):
|
|
|
|
|
|
|
|
|
|
model = Document
|
|
|
|
|
|
|
|
|
|
def render_to_response(self, context, **response_kwargs):
|
|
|
|
|
"""
|
|
|
|
|
Override the default to return the unencrypted PDF as raw data.
|
|
|
|
|
"""
|
|
|
|
|
|
2016-01-14 19:47:57 +00:00
|
|
|
response = HttpResponse(
|
|
|
|
|
GnuPG.decrypted(self.object.pdf), content_type="application/pdf")
|
2016-01-01 16:13:59 +00:00
|
|
|
response["Content-Disposition"] = 'attachment; filename="{}"'.format(
|
|
|
|
|
slugify(str(self.object)) + ".pdf")
|
|
|
|
|
|
|
|
|
|
return response
|