Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Merge remote-tracking branch 'upstream/master'

Jonas Winkler94ede7389d1e
diff --cc requirements.txt
index 89c7e296f,b8c26a579..84ec2e68b
--- a/requirements.txt
+++ b/requirements.txt
@@@ -24,20 -24,19 +24,20 @@@ idna==2.
inotify-simple==1.1.8
langdetect==1.0.7
more-itertools==4.3.0
+numpy==1.15.1
pdftotext==2.1.0
pillow==5.2.0
- pluggy==0.7.1; python_version != '3.1.*'
- py==1.6.0; python_version != '3.1.*'
+ pluggy==0.7.1; python_version != '3.3.*'
+ py==1.6.0; python_version != '3.3.*'
pycodestyle==2.4.0
pyocr==0.5.3
- pytest-cov==2.5.1
+ pytest-cov==2.6.0
pytest-django==3.4.2
pytest-env==0.6.2
- pytest-forked==0.2
+ pytest-forked==0.2; python_version != '3.3.*'
pytest-sugar==0.9.1
pytest-xdist==1.23.0
- pytest==3.7.4
+ pytest==3.8.0
python-dateutil==2.7.3
python-dotenv==0.9.1
python-gnupg==0.4.3
diff --cc src/documents/actions.py
index 0b68d6c89,cd2698a2c..96ce893aa
mode 100644,100644..100755
--- a/src/documents/actions.py
+++ b/src/documents/actions.py
@@@ -4,11 -4,13 +4,14 @@@ from django.contrib.admin.utils import
from django.core.exceptions import PermissionDenied
from django.template.response import TemplateResponse
-from documents.models import Correspondent, Tag
+from documents.classifier import DocumentClassifier
- from documents.models import Tag, Correspondent, DocumentType
++from documents.models import Correspondent, DocumentType, Tag
- def select_action(modeladmin, request, queryset, title, action, modelclass, success_message="", document_action=None, queryset_action=None):
+ def select_action(
+ modeladmin, request, queryset, title, action, modelclass,
+ success_message="", document_action=None, queryset_action=None):
+
opts = modeladmin.model._meta
app_label = opts.app_label
@@@ -103,36 -127,20 +128,50 @@@ def set_correspondent_on_selected(model
def remove_correspondent_from_selected(modeladmin, request, queryset):
- return simple_action(modeladmin=modeladmin, request=request, queryset=queryset,
- success_message="Successfully removed correspondent from %(count)d %(items)s.",
- queryset_action=lambda qs: qs.update(correspondent=None))
- remove_correspondent_from_selected.short_description = "Remove correspondent from selected documents"
+ return simple_action(
+ modeladmin=modeladmin,
+ request=request,
+ queryset=queryset,
+ success_message="Successfully removed correspondent from %(count)d "
+ "%(items)s.",
+ queryset_action=lambda qs: qs.update(correspondent=None)
+ )
+def set_document_type_on_selected(modeladmin, request, queryset):
+ return select_action(modeladmin=modeladmin, request=request, queryset=queryset,
+ title="Set document type on multiple documents",
+ 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 qs, document_type: qs.update(document_type=document_type))
- set_document_type_on_selected.short_description = "Set document type on selected documents"
+
+
+def remove_document_type_from_selected(modeladmin, request, queryset):
+ return simple_action(modeladmin=modeladmin, request=request, queryset=queryset,
+ success_message="Successfully removed document type from %(count)d %(items)s.",
+ queryset_action=lambda qs: qs.update(document_type=None))
- remove_document_type_from_selected.short_description = "Remove document type from selected documents"
+
+
+def run_document_classifier_on_selected(modeladmin, request, queryset):
+ try:
+ clf = DocumentClassifier.load_classifier()
+ return simple_action(modeladmin=modeladmin, request=request, queryset=queryset,
+ success_message="Successfully applied document classifier to %(count)d %(items)s.",
+ document_action=lambda doc: clf.classify_document(doc, classify_correspondent=True, classify_tags=True, classify_document_type=True))
+ except FileNotFoundError:
+ modeladmin.message_user(request, "Classifier model file not found.", messages.ERROR)
+ return None
++
++
+ add_tag_to_selected.short_description = "Add tag to selected documents"
+ remove_tag_from_selected.short_description = \
+ "Remove tag from selected documents"
+ set_correspondent_on_selected.short_description = \
+ "Set correspondent on selected documents"
+ remove_correspondent_from_selected.short_description = \
+ "Remove correspondent from selected documents"
++set_document_type_on_selected.short_description = "Set document type on selected documents"
++remove_document_type_from_selected.short_description = "Remove document type from selected documents"
+run_document_classifier_on_selected.short_description = "Run document classifier on selected"
++
diff --cc src/documents/admin.py
index 7386ebef1,365a99c1a..d739011d4
mode 100644,100644..100755
--- a/src/documents/admin.py
+++ b/src/documents/admin.py
@@@ -13,12 -11,15 +11,18 @@@ from django.urls import revers
from django.utils.html import format_html, format_html_join
from django.utils.http import urlquote
from django.utils.safestring import mark_safe
- from django.db import models
- from documents.actions import add_tag_to_selected, remove_tag_from_selected, set_correspondent_on_selected, \
- remove_correspondent_from_selected, set_document_type_on_selected, remove_document_type_from_selected, \
+ from documents.actions import (
+ add_tag_to_selected,
+ remove_correspondent_from_selected,
+ remove_tag_from_selected,
- set_correspondent_on_selected
++ set_correspondent_on_selected,
++ set_document_type_on_selected,
++ remove_document_type_from_selected,
+ run_document_classifier_on_selected
- from .models import Correspondent, Tag, Document, Log, DocumentType
+ )
+
-from .models import Correspondent, Document, Log, Tag
++from .models import Correspondent, Document, DocumentType, Log, Tag
class FinancialYearFilter(admin.SimpleListFilter):
@@@ -107,8 -115,15 +118,13 @@@ class CommonAdmin(admin.ModelAdmin)
class CorrespondentAdmin(CommonAdmin):
- list_display = ("name", "automatic_classification", "document_count", "last_correspondence")
- list_editable = ("automatic_classification",)
+ list_display = (
+ "name",
- "match",
- "matching_algorithm",
++ "automatic_classification",
+ "document_count",
+ "last_correspondence"
+ )
- list_filter = ("matching_algorithm",)
- list_editable = ("match", "matching_algorithm")
++ list_editable = ("automatic_classification")
def get_queryset(self, request):
qs = super(CorrespondentAdmin, self).get_queryset(request)
@@@ -166,18 -169,30 +184,34 @@@ class DocumentAdmin(CommonAdmin)
search_fields = ("correspondent__name", "title", "content", "tags__name")
readonly_fields = ("added",)
list_display = ("title", "created", "added", "thumbnail", "correspondent",
- "tags_")
+ "tags_", "archive_serial_number", "document_type")
- list_filter = ("document_type", "tags", ('correspondent', RecentCorrespondentFilter), "correspondent", FinancialYearFilter)
+ list_filter = (
++ "document_type",
+ "tags",
+ ("correspondent", RecentCorrespondentFilter),
+ "correspondent",
+ FinancialYearFilter
+ )
filter_horizontal = ("tags",)
ordering = ["-created", "correspondent"]
- actions = [add_tag_to_selected, remove_tag_from_selected, set_correspondent_on_selected, remove_correspondent_from_selected, set_document_type_on_selected, remove_document_type_from_selected, run_document_classifier_on_selected]
+ actions = [
+ add_tag_to_selected,
+ remove_tag_from_selected,
+ set_correspondent_on_selected,
- remove_correspondent_from_selected
++ remove_correspondent_from_selected,
++ set_document_type_on_selected,
++ remove_document_type_from_selected,
++ run_document_classifier_on_selected
+ ]
- date_hierarchy = 'created'
+ date_hierarchy = "created"
- document_queue = None
+ def __init__(self, *args, **kwargs):
+ super().__init__(*args, **kwargs)
+ self.document_queue = []
def has_add_permission(self, request):
return False
@@@ -195,19 -214,26 +233,29 @@@
return response
- def change_view(self, request, object_id=None, form_url='', extra_context=None):
+ def change_view(self, request, object_id=None, form_url='',
+ extra_context=None):
+
extra_context = extra_context or {}
+ doc = Document.objects.get(id=object_id)
+ 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
- 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
- extra_context['next_object'] = self.document_queue[current_index + 1]
+
+ if self.document_queue and object_id:
+ if int(object_id) in self.document_queue:
+ # 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
+ 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,
+ request,
+ object_id,
+ form_url,
+ extra_context=extra_context,
)
def response_change(self, request, obj):
diff --cc src/documents/filters.py
index 780491a14,d52889666..ae0e0d22e
mode 100644,100644..100755
--- a/src/documents/filters.py
+++ b/src/documents/filters.py
@@@ -1,8 -1,14 +1,14 @@@
- from django_filters.rest_framework import CharFilter, FilterSet, BooleanFilter
+ from django_filters.rest_framework import CharFilter, FilterSet, BooleanFilter, ModelChoiceFilter
-from .models import Correspondent, Document, Tag
+from .models import Correspondent, Document, Tag, DocumentType
+ CHAR_KWARGS = (
+ "startswith", "endswith", "contains",
+ "istartswith", "iendswith", "icontains"
+ )
+
+
class CorrespondentFilterSet(FilterSet):
class Meta:
@@@ -29,53 -35,26 +35,42 @@@ class TagFilterSet(FilterSet)
}
+class DocumentTypeFilterSet(FilterSet):
+
+ class Meta(object):
+ model = DocumentType
+ fields = {
+ "name": [
+ "startswith", "endswith", "contains",
+ "istartswith", "iendswith", "icontains"
+ ],
+ "slug": ["istartswith", "iendswith", "icontains"]
+ }
+
+
class DocumentFilterSet(FilterSet):
- CHAR_KWARGS = {
- "lookup_expr": (
- "startswith",
- "endswith",
- "contains",
- "istartswith",
- "iendswith",
- "icontains"
- )
- }
-
- correspondent__name = CharFilter(
- field_name="correspondent__name", **CHAR_KWARGS)
- correspondent__slug = CharFilter(
- field_name="correspondent__slug", **CHAR_KWARGS)
- tags__name = CharFilter(
- field_name="tags__name", **CHAR_KWARGS)
- tags__slug = CharFilter(
- field_name="tags__slug", **CHAR_KWARGS)
- tags__empty = BooleanFilter(
- field_name="tags", lookup_expr="isnull", distinct=True)
- document_type__name = CharFilter(
- name="document_type__name", **CHAR_KWARGS)
- document_type__slug = CharFilter(
- name="document_type__slug", **CHAR_KWARGS)
+ tags_empty = BooleanFilter(
+ label="Is tagged",
+ field_name="tags",
+ lookup_expr="isnull",
+ exclude=True
+ )
class Meta:
model = Document
fields = {
- "title": [
- "startswith", "endswith", "contains",
- "istartswith", "iendswith", "icontains"
- ],
- "content": ["contains", "icontains"],
+
+ "title": CHAR_KWARGS,
+ "content": ("contains", "icontains"),
+
+ "correspondent__name": CHAR_KWARGS,
+ "correspondent__slug": CHAR_KWARGS,
+
+ "tags__name": CHAR_KWARGS,
+ "tags__slug": CHAR_KWARGS,
+
++ "document_type__name": CHAR_KWARGS,
++ "document_type__slug": CHAR_KWARGS,
++
}
diff --cc src/documents/templates/admin/documents/document/select_object.html
index 1439b5c21,775d57b12..775d57b12
mode 100644,100644..100755
--- a/src/documents/templates/admin/documents/document/select_object.html
+++ b/src/documents/templates/admin/documents/document/select_object.html
diff --cc src/paperless/settings.py
index faecc3569,4e788e56b..b3725f4b6
mode 100644,100644..100755
--- a/src/paperless/settings.py
+++ b/src/paperless/settings.py
@@@ -144,13 -144,14 +144,14 @@@ DATABASES =
}
}
-if os.getenv("PAPERLESS_DBUSER"):
+if os.getenv("PAPERLESS_DBENGINE"):
DATABASES["default"] = {
- "ENGINE": "django.db.backends.postgresql_psycopg2",
+ "ENGINE": os.getenv("PAPERLESS_DBENGINE"),
"NAME": os.getenv("PAPERLESS_DBNAME", "paperless"),
"USER": os.getenv("PAPERLESS_DBUSER"),
- "PASSWORD": os.getenv("PAPERLESS_DBPASS")
}
+ if os.getenv("PAPERLESS_DBPASS"):
+ DATABASES["default"]["PASSWORD"] = os.getenv("PAPERLESS_DBPASS")
# Password validation