From 22378789e2a112bf71d499236a5c1da11fc7b0e7 Mon Sep 17 00:00:00 2001 From: Joshua Taillon Date: Wed, 5 Sep 2018 22:58:38 -0400 Subject: [PATCH 1/3] add option for inline vs. attachment for document rendering --- paperless.conf.example | 4 ++++ src/documents/views.py | 10 ++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/paperless.conf.example b/paperless.conf.example index d47e4d453..996b816f8 100644 --- a/paperless.conf.example +++ b/paperless.conf.example @@ -117,6 +117,10 @@ PAPERLESS_EMAIL_SECRET="" # http://paperless.readthedocs.org/en/latest/consumption.html#hooking-into-the-consumption-process #PAPERLESS_POST_CONSUME_SCRIPT="/path/to/an/arbitrary/script.sh" +# By default, when clicking on a document within the web interface, the +# browser will prompt the user to save the document to disk. By uncommenting +# the below, the document will instead be opened in the browser, if possible. +#PAPERLESS_INLINE_DOC="true" # # The following values use sensible defaults for modern systems, but if you're diff --git a/src/documents/views.py b/src/documents/views.py index e297e0984..4f71deb56 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -1,6 +1,8 @@ from django.http import HttpResponse, HttpResponseBadRequest from django.views.generic import DetailView, FormView, TemplateView from django_filters.rest_framework import DjangoFilterBackend +from django.conf import settings + from paperless.db import GnuPG from paperless.mixins import SessionOrBasicAuthMixin from paperless.views import StandardPagination @@ -60,8 +62,12 @@ class FetchView(SessionOrBasicAuthMixin, DetailView): self._get_raw_data(self.object.source_file), content_type=content_types[self.object.file_type] ) - response["Content-Disposition"] = 'attachment; filename="{}"'.format( - self.object.file_name) + + print("OPEN_DOCUMENT", settings.INLINE_DOC) + DISPOSITION = 'inline' if settings.INLINE_DOC else 'attachment' + + response["Content-Disposition"] = '{}; filename="{}"'.format( + DISPOSITION, self.object.file_name) return response From be9757894a385963479e9a85abb35697b6497c44 Mon Sep 17 00:00:00 2001 From: Joshua Taillon Date: Wed, 5 Sep 2018 23:03:30 -0400 Subject: [PATCH 2/3] add INLINE_DOC to settings.py --- src/paperless/settings.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 06cc1807f..56360d5d5 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -270,6 +270,9 @@ PASSPHRASE = os.getenv("PAPERLESS_PASSPHRASE") PRE_CONSUME_SCRIPT = os.getenv("PAPERLESS_PRE_CONSUME_SCRIPT") POST_CONSUME_SCRIPT = os.getenv("PAPERLESS_POST_CONSUME_SCRIPT") +# Whether to display a selected document inline, or download it as attachment: +INLINE_DOC = os.getenv("PAPERLESS_INLINE_DOC") + # The number of items on each page in the web UI. This value must be a # positive integer, but if you don't define one in paperless.conf, a default of # 100 will be used. From 652ead2f5ccfbeb15c5d743c2e6159b3d07fbd78 Mon Sep 17 00:00:00 2001 From: Joshua Taillon Date: Wed, 5 Sep 2018 23:05:37 -0400 Subject: [PATCH 3/3] remove debugging print statement --- src/documents/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/documents/views.py b/src/documents/views.py index 4f71deb56..6e4eeafd2 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -63,7 +63,6 @@ class FetchView(SessionOrBasicAuthMixin, DetailView): content_type=content_types[self.object.file_type] ) - print("OPEN_DOCUMENT", settings.INLINE_DOC) DISPOSITION = 'inline' if settings.INLINE_DOC else 'attachment' response["Content-Disposition"] = '{}; filename="{}"'.format(