Files
paperless-ngx/src/documents/views.py

35 lines
1008 B
Python
Raw Normal View History

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
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-29 23:18:03 +00:00
content_types = {
Document.TYPE_PDF: "application/pdf",
Document.TYPE_PNG: "image/png",
Document.TYPE_JPG: "image/jpeg",
Document.TYPE_GIF: "image/gif",
Document.TYPE_TIF: "image/tiff",
}
response = HttpResponse(
2016-01-29 23:18:03 +00:00
GnuPG.decrypted(self.object.source_file),
content_type=content_types[self.object.file_type]
)
2016-01-01 16:13:59 +00:00
response["Content-Disposition"] = 'attachment; filename="{}"'.format(
2016-01-29 23:18:03 +00:00
slugify(str(self.object)) + "." + self.object.file_type)
2016-01-01 16:13:59 +00:00
return response