A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
- added recent correspondents filter - sortable document_count fields - added last correspondence field to CorrespondentAdmin
Jonas Winkler781a1dae711b
diff --git a/paperless.conf.example b/paperless.conf.exampleindex 424e046fb..d42d5ca5f 100755--- a/paperless.conf.example+++ b/paperless.conf.example@@ -204,3 +204,7 @@ PAPERLESS_EMAIL_SECRET=""# 100 will be used.#PAPERLESS_LIST_PER_PAGE=100++# The number of years for which a correspondent will be included in the recent+# correspondents filter.+#PAPERLESS_RECENT_CORRESPONDENT_YEARS=2\ No newline at end of filediff --git a/src/documents/admin.py b/src/documents/admin.pyindex d0cd23e9b..65548d91f 100755--- a/src/documents/admin.py+++ b/src/documents/admin.py@@ -1,4 +1,4 @@-from datetime import datetime+from datetime import datetime, timedeltafrom django.conf import settingsfrom django.contrib import admin, messages@@ -10,6 +10,7 @@ from django.templatetags.static import staticfrom django.utils.html import format_htmlfrom django.utils.http import urlquotefrom django.utils.safestring import mark_safe+from django.db import modelsfrom 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@@ -81,13 +82,27 @@ class FinancialYearFilter(admin.SimpleListFilter):created__lte=self._fy_end(end))+class RecentCorrespondentFilter(admin.RelatedFieldListFilter):++ def __init__(self, *args, **kwargs):+ super().__init__(*args, **kwargs)+ self.title = "correspondent (recent)"++ 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) )+ return lookups++class CommonAdmin(admin.ModelAdmin):list_per_page = settings.PAPERLESS_LIST_PER_PAGEclass CorrespondentAdmin(CommonAdmin):- list_display = ("name", "match", "matching_algorithm", "document_count")+ list_display = ("name", "match", "matching_algorithm", "document_count", "last_correspondence")list_filter = ("matching_algorithm",)list_editable = ("match", "matching_algorithm")@@ -99,8 +114,18 @@ class CorrespondentAdmin(CommonAdmin):document.correspondent = objdocument.save(update_fields=("correspondent",))+ def get_queryset(self, request):+ qs = super(CorrespondentAdmin, self).get_queryset(request)+ qs = qs.annotate(document_count=models.Count("documents"), last_correspondence=models.Max("documents__created"))+ return qs+def document_count(self, obj):- return obj.documents.count()+ return obj.document_count+ document_count.admin_order_field = "document_count"++ def last_correspondence(self, obj):+ return obj.last_correspondence+ last_correspondence.admin_order_field = "last_correspondence"class TagAdmin(CommonAdmin):@@ -117,8 +142,15 @@ class TagAdmin(CommonAdmin):if obj.matches(document.content):document.tags.add(obj)+ def get_queryset(self, request):+ qs = super(TagAdmin, self).get_queryset(request)+ qs = qs.annotate(document_count=models.Count("documents"))+ return qs+def document_count(self, obj):- return obj.documents.count()+ return obj.document_count+ document_count.admin_order_field = "document_count"+class DocumentTypeAdmin(CommonAdmin):@@ -134,8 +166,14 @@ class DocumentTypeAdmin(CommonAdmin):document.document_type = objdocument.save(update_fields=("document_type",))+ def get_queryset(self, request):+ qs = super(DocumentTypeAdmin, self).get_queryset(request)+ qs = qs.annotate(document_count=models.Count("documents"))+ return qs+def document_count(self, obj):- return obj.documents.count()+ return obj.document_count+ document_count.admin_order_field = "document_count"class DocumentAdmin(CommonAdmin):@@ -149,7 +187,7 @@ class DocumentAdmin(CommonAdmin):readonly_fields = ("added",)list_display = ("title", "created", "added", "thumbnail", "correspondent","tags_", "archive_serial_number", "document_type")- list_filter = ("document_type", "tags", "correspondent", FinancialYearFilter)+ list_filter = ("document_type", "tags", ('correspondent', RecentCorrespondentFilter), "correspondent", FinancialYearFilter)ordering = ["-created", "correspondent"]diff --git a/src/paperless/settings.py b/src/paperless/settings.pyindex b52cf1ca8..f354d5abf 100755--- a/src/paperless/settings.py+++ b/src/paperless/settings.py@@ -278,3 +278,5 @@ 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", 2))