From 22378789e2a112bf71d499236a5c1da11fc7b0e7 Mon Sep 17 00:00:00 2001 From: Joshua Taillon Date: Wed, 5 Sep 2018 22:58:38 -0400 Subject: [PATCH 1/5] 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 @@ def render_to_response(self, context, **response_kwargs): 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/5] 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 @@ 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/5] 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 @@ def render_to_response(self, context, **response_kwargs): 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( From a86a20ef0f50184aad724ba6bddfd426faa27b65 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Sun, 9 Sep 2018 21:16:53 +0100 Subject: [PATCH 4/5] Make the example file contain the default value --- paperless.conf.example | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/paperless.conf.example b/paperless.conf.example index 996b816f8..15498a26a 100644 --- a/paperless.conf.example +++ b/paperless.conf.example @@ -118,9 +118,9 @@ PAPERLESS_EMAIL_SECRET="" #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" +# browser will prompt the user to save the document to disk. By setting this to +# "true", the document will instead be opened in the browser, if possible. +#PAPERLESS_INLINE_DOC="false" # # The following values use sensible defaults for modern systems, but if you're From 7cef1087851de36a4a1c156224257f544d0f62d1 Mon Sep 17 00:00:00 2001 From: Daniel Quinn Date: Sun, 9 Sep 2018 21:22:07 +0100 Subject: [PATCH 5/5] Streamline how we handle boolean values in settings.py --- src/paperless/settings.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/paperless/settings.py b/src/paperless/settings.py index 280d737e9..956b90a7f 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -22,6 +22,14 @@ load_dotenv("/usr/local/etc/paperless.conf") +def __get_boolean(key): + """ + Return a boolean value based on whatever the user has supplied in the + environment based on whether the value "looks like" it's True or not. + """ + return bool(os.getenv(key, "NO").lower() in ("yes", "y", "1", "t", "true")) + + # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) @@ -222,12 +230,12 @@ OCR_THREADS = os.getenv("PAPERLESS_OCR_THREADS") # OCR all documents? -OCR_ALWAYS = bool(os.getenv("PAPERLESS_OCR_ALWAYS", "NO").lower() in ("yes", "y", "1", "t", "true")) # NOQA +OCR_ALWAYS = __get_boolean("PAPERLESS_OCR_ALWAYS") # If this is true, any failed attempts to OCR a PDF will result in the PDF # being indexed anyway, with whatever we could get. If it's False, the file # will simply be left in the CONSUMPTION_DIR. -FORGIVING_OCR = bool(os.getenv("PAPERLESS_FORGIVING_OCR", "YES").lower() in ("yes", "y", "1", "t", "true")) # NOQA +FORGIVING_OCR = __get_boolean("PAPERLESS_FORGIVING_OCR") # GNUPG needs a home directory for some reason GNUPG_HOME = os.getenv("HOME", "/tmp") @@ -272,7 +280,7 @@ 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") +INLINE_DOC = __get_boolean("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