From 8d003a6a854f66d57f50c363ab2e81770996d5bf Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Thu, 13 Sep 2018 13:10:05 +0200 Subject: [PATCH 1/2] Save and edit next button appears on documents without viewer as well. Made the new recent correspondents filter optional. Disabled by default. --- src/documents/admin.py | 7 +- .../admin/documents/document/change_form.html | 25 +-- .../documents/document/select_object.html | 4 +- .../document/viewers/viewer_image.html | 1 - .../document/viewers/viewer_pdf.html | 163 ++++++++++-------- src/paperless/settings.py | 6 +- 6 files changed, 111 insertions(+), 95 deletions(-) mode change 100755 => 100644 src/documents/templates/admin/documents/document/change_form.html mode change 100755 => 100644 src/documents/templates/admin/documents/document/viewers/viewer_image.html mode change 100755 => 100644 src/documents/templates/admin/documents/document/viewers/viewer_pdf.html diff --git a/src/documents/admin.py b/src/documents/admin.py index 7f3886354..6446d45d4 100644 --- a/src/documents/admin.py +++ b/src/documents/admin.py @@ -94,9 +94,10 @@ class RecentCorrespondentFilter(admin.RelatedFieldListFilter): def field_choices(self, field, request, model_admin): lookups = [] - date_limit = datetime.now() - timedelta(days=365*settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS) - for c in Correspondent.objects.filter(documents__created__gte = date_limit).distinct(): - lookups.append( (c.id, c.name) ) + if settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS and settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS > 0: + date_limit = datetime.now() - timedelta(days=365*settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS) + for c in Correspondent.objects.filter(documents__created__gte = date_limit).distinct(): + lookups.append( (c.id, c.name) ) return lookups diff --git a/src/documents/templates/admin/documents/document/change_form.html b/src/documents/templates/admin/documents/document/change_form.html old mode 100755 new mode 100644 index 9f184415c..d33a3ec67 --- a/src/documents/templates/admin/documents/document/change_form.html +++ b/src/documents/templates/admin/documents/document/change_form.html @@ -4,7 +4,7 @@ {{ block.super }} -{% if file_type in "pdf jpg png" %} +{% if file_type in "asd" %}
@@ -23,16 +23,17 @@ django.jQuery("#content-main").append(django.jQuery("#change_form_twocolumn_parent")); - {% if next_object %} - - {% endif %} +{% endif %} + +{% if next_object %} + {% endif %} {% endblock content %} @@ -46,4 +47,4 @@ django.jQuery(".field-created input").first().attr("type", "date") -{% endblock footer %} \ No newline at end of file +{% endblock footer %} diff --git a/src/documents/templates/admin/documents/document/select_object.html b/src/documents/templates/admin/documents/document/select_object.html index 249814d28..1439b5c21 100644 --- a/src/documents/templates/admin/documents/document/select_object.html +++ b/src/documents/templates/admin/documents/document/select_object.html @@ -38,9 +38,9 @@

- + {% trans "Go back" %}

-{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/src/documents/templates/admin/documents/document/viewers/viewer_image.html b/src/documents/templates/admin/documents/document/viewers/viewer_image.html old mode 100755 new mode 100644 index 9e572d74a..3f860a90c --- a/src/documents/templates/admin/documents/document/viewers/viewer_image.html +++ b/src/documents/templates/admin/documents/document/viewers/viewer_image.html @@ -1,2 +1 @@ - diff --git a/src/documents/templates/admin/documents/document/viewers/viewer_pdf.html b/src/documents/templates/admin/documents/document/viewers/viewer_pdf.html old mode 100755 new mode 100644 index 4e223d935..5440a4cac --- a/src/documents/templates/admin/documents/document/viewers/viewer_pdf.html +++ b/src/documents/templates/admin/documents/document/viewers/viewer_pdf.html @@ -3,117 +3,128 @@
-     - Page: / -     +     + Page: / +    
- -
+ + - {# Load and display PDF document#} - +}); + diff --git a/src/paperless/settings.py b/src/paperless/settings.py index c303114e3..faecc3569 100644 --- a/src/paperless/settings.py +++ b/src/paperless/settings.py @@ -298,4 +298,8 @@ FY_END = os.getenv("PAPERLESS_FINANCIAL_YEAR_END") # Specify the default date order (for autodetected dates) DATE_ORDER = os.getenv("PAPERLESS_DATE_ORDER", "DMY") -PAPERLESS_RECENT_CORRESPONDENT_YEARS = int(os.getenv("PAPERLESS_RECENT_CORRESPONDENT_YEARS", 1)) +# Specify for how many years a correspondent is considered recent. Recent +# correspondents will be shown in a separate "Recent correspondents" filter as +# well. Set to 0 to disable this filter. +PAPERLESS_RECENT_CORRESPONDENT_YEARS = int(os.getenv( + "PAPERLESS_RECENT_CORRESPONDENT_YEARS", 0)) From 909586bf25af6feaea8f191c88a5dfadcbcd0c1e Mon Sep 17 00:00:00 2001 From: Jonas Winkler Date: Thu, 13 Sep 2018 14:15:16 +0200 Subject: [PATCH 2/2] Code style changed --- src/documents/actions.py | 11 +++++------ src/documents/admin.py | 9 +++++---- src/documents/classifier.py | 2 +- .../management/commands/document_create_classifier.py | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/documents/actions.py b/src/documents/actions.py index 02b5d904a..0b68d6c89 100644 --- a/src/documents/actions.py +++ b/src/documents/actions.py @@ -43,14 +43,12 @@ def select_action(modeladmin, request, queryset, title, action, modelclass, succ media=modeladmin.media, action=action, objects=modelclass.objects.all(), - itemname=model_ngettext(modelclass,1) + itemname=model_ngettext(modelclass, 1) ) request.current_app = modeladmin.admin_site.name - return TemplateResponse(request, - "admin/%s/%s/select_object.html" % (app_label, opts.model_name) - , context) + return TemplateResponse(request, "admin/%s/%s/select_object.html" % (app_label, opts.model_name), context) def simple_action(modeladmin, request, queryset, success_message="", document_action=None, queryset_action=None): @@ -70,6 +68,7 @@ def simple_action(modeladmin, request, queryset, success_message="", document_ac "count": n, "items": model_ngettext(modeladmin.opts, n) }, messages.SUCCESS) + # Return None to display the change list page again. return None @@ -99,7 +98,7 @@ def set_correspondent_on_selected(modeladmin, request, queryset): action="set_correspondent_on_selected", modelclass=Correspondent, success_message="Successfully set correspondent %(selected_object)s on %(count)d %(items)s.", - queryset_action=lambda queryset, correspondent: queryset.update(correspondent=correspondent)) + queryset_action=lambda qs, correspondent: qs.update(correspondent=correspondent)) set_correspondent_on_selected.short_description = "Set correspondent on selected documents" @@ -116,7 +115,7 @@ def set_document_type_on_selected(modeladmin, request, queryset): action="set_document_type_on_selected", modelclass=DocumentType, success_message="Successfully set document type %(selected_object)s on %(count)d %(items)s.", - queryset_action=lambda queryset, document_type: queryset.update(document_type=document_type)) + queryset_action=lambda qs, document_type: qs.update(document_type=document_type)) set_document_type_on_selected.short_description = "Set document type on selected documents" diff --git a/src/documents/admin.py b/src/documents/admin.py index 6446d45d4..7386ebef1 100644 --- a/src/documents/admin.py +++ b/src/documents/admin.py @@ -96,8 +96,8 @@ class RecentCorrespondentFilter(admin.RelatedFieldListFilter): lookups = [] if settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS and settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS > 0: date_limit = datetime.now() - timedelta(days=365*settings.PAPERLESS_RECENT_CORRESPONDENT_YEARS) - for c in Correspondent.objects.filter(documents__created__gte = date_limit).distinct(): - lookups.append( (c.id, c.name) ) + for c in Correspondent.objects.filter(documents__created__gte=date_limit).distinct(): + lookups.append((c.id, c.name)) return lookups @@ -154,6 +154,7 @@ class DocumentTypeAdmin(CommonAdmin): return obj.document_count document_count.admin_order_field = "document_count" + class DocumentAdmin(CommonAdmin): class Media: @@ -200,10 +201,10 @@ class DocumentAdmin(CommonAdmin): extra_context['download_url'] = doc.download_url extra_context['file_type'] = doc.file_type if self.document_queue and object_id and int(object_id) in self.document_queue: - #There is a queue of documents + # There is a queue of documents current_index = self.document_queue.index(int(object_id)) if current_index < len(self.document_queue) - 1: - #... and there are still documents in the queue + # ... and there are still documents in the queue extra_context['next_object'] = self.document_queue[current_index + 1] return super(DocumentAdmin, self).change_view( request, object_id, form_url, extra_context=extra_context, diff --git a/src/documents/classifier.py b/src/documents/classifier.py index 1fc46a3f1..8e76e0f02 100644 --- a/src/documents/classifier.py +++ b/src/documents/classifier.py @@ -127,7 +127,7 @@ class DocumentClassifier(object): def classify_document(self, document, classify_correspondent=False, classify_document_type=False, classify_tags=False, replace_tags=False): X = self.data_vectorizer.transform([preprocess_content(document.content)]) - update_fields=() + update_fields = () if classify_correspondent and self.correspondent_classifier is not None: y_correspondent = self.correspondent_classifier.predict(X) diff --git a/src/documents/management/commands/document_create_classifier.py b/src/documents/management/commands/document_create_classifier.py index bcd91f8db..610fa4898 100644 --- a/src/documents/management/commands/document_create_classifier.py +++ b/src/documents/management/commands/document_create_classifier.py @@ -3,7 +3,7 @@ import os.path import pickle from django.core.management.base import BaseCommand -from documents.classifier import DocumentClassifier +from documents.classifier import DocumentClassifier from paperless import settings from ...mixins import Renderable