Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
added
Browse files Browse the repository at this point in the history
- document index
- api access for thumbnails/downloads
- more api filters

updated
- pipfile

removed
- filename handling
- legacy thumb/download access
- obsolete admin gui settings (per page items, FY, inline view)
  • Loading branch information
Jonas Winkler committed Oct 25, 2020
1 parent 9187026 commit 052c168
Show file tree
Hide file tree
Showing 16 changed files with 330 additions and 575 deletions.
143 changes: 67 additions & 76 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions paperless.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ PAPERLESS_CONSUMPTION_DIR=""
#PAPERLESS_STATICDIR=""


# This is where the whoosh document index is stored
#PAPERLESS_INDEX_DIR="/path/to/index"


# Override the MEDIA_URL here. Unless you're hosting Paperless off a subdomain
# like /paperless/, you probably don't need to change this.
#PAPERLESS_MEDIA_URL="/media/"
Expand Down Expand Up @@ -262,18 +266,6 @@ PAPERLESS_EMAIL_SECRET=""
#PAPERLESS_TIME_ZONE=UTC


# If set, Paperless will show document filters per financial year.
# The dates must be in the format "mm-dd", for example "07-15" for July 15.
#PAPERLESS_FINANCIAL_YEAR_START="mm-dd"
#PAPERLESS_FINANCIAL_YEAR_END="mm-dd"


# 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.
#PAPERLESS_LIST_PER_PAGE=100


###############################################################################
#### Third-Party Binaries ####
###############################################################################
Expand Down
86 changes: 6 additions & 80 deletions src/documents/admin.py
Original file line number Diff line number Diff line change
@@ -1,85 +1,12 @@
from datetime import datetime

from django.conf import settings
from django.contrib import admin
from django.contrib.auth.models import Group, User
from django.db import models
from django.utils.html import format_html, format_html_join
from django.utils.safestring import mark_safe

from .models import Correspondent, Document, DocumentType, Log, Tag


class FinancialYearFilter(admin.SimpleListFilter):

title = "Financial Year"
parameter_name = "fy"
_fy_wraps = None

def _fy_start(self, year):
"""Return date of the start of financial year for the given year."""
fy_start = "{}-{}".format(str(year), settings.FY_START)
return datetime.strptime(fy_start, "%Y-%m-%d").date()

def _fy_end(self, year):
"""Return date of the end of financial year for the given year."""
fy_end = "{}-{}".format(str(year), settings.FY_END)
return datetime.strptime(fy_end, "%Y-%m-%d").date()

def _fy_does_wrap(self):
"""Return whether the financial year spans across two years."""
if self._fy_wraps is None:
start = "{}".format(settings.FY_START)
start = datetime.strptime(start, "%m-%d").date()
end = "{}".format(settings.FY_END)
end = datetime.strptime(end, "%m-%d").date()
self._fy_wraps = end < start

return self._fy_wraps

def _determine_fy(self, date):
"""Return a (query, display) financial year tuple of the given date."""
if self._fy_does_wrap():
fy_start = self._fy_start(date.year)

if date.date() >= fy_start:
query = "{}-{}".format(date.year, date.year + 1)
else:
query = "{}-{}".format(date.year - 1, date.year)

# To keep it simple we use the same string for both
# query parameter and the display.
return query, query

else:
query = "{0}-{0}".format(date.year)
display = "{}".format(date.year)
return query, display

def lookups(self, request, model_admin):
if not settings.FY_START or not settings.FY_END:
return None

r = []
for document in Document.objects.all():
r.append(self._determine_fy(document.created))

return sorted(set(r), key=lambda x: x[0], reverse=True)

def queryset(self, request, queryset):
if not self.value() or not settings.FY_START or not settings.FY_END:
return None

start, end = self.value().split("-")
return queryset.filter(created__gte=self._fy_start(start),
created__lte=self._fy_end(end))


class CommonAdmin(admin.ModelAdmin):
list_per_page = settings.PAPERLESS_LIST_PER_PAGE


class CorrespondentAdmin(CommonAdmin):
class CorrespondentAdmin(admin.ModelAdmin):

list_display = (
"name",
Expand All @@ -90,7 +17,7 @@ class CorrespondentAdmin(CommonAdmin):
readonly_fields = ("slug",)


class TagAdmin(CommonAdmin):
class TagAdmin(admin.ModelAdmin):

list_display = (
"name",
Expand All @@ -104,7 +31,7 @@ class TagAdmin(CommonAdmin):
readonly_fields = ("slug",)


class DocumentTypeAdmin(CommonAdmin):
class DocumentTypeAdmin(admin.ModelAdmin):

list_display = (
"name",
Expand All @@ -116,7 +43,7 @@ class DocumentTypeAdmin(CommonAdmin):
readonly_fields = ("slug",)


class DocumentAdmin(CommonAdmin):
class DocumentAdmin(admin.ModelAdmin):

search_fields = ("correspondent__name", "title", "content", "tags__name")
readonly_fields = ("added", "file_type", "storage_type",)
Expand All @@ -125,8 +52,7 @@ class DocumentAdmin(CommonAdmin):
list_filter = (
"document_type",
"tags",
"correspondent",
FinancialYearFilter
"correspondent"
)

filter_horizontal = ("tags",)
Expand Down Expand Up @@ -164,7 +90,7 @@ def _html_tag(kind, inside=None, **kwargs):
return format_html("<{} {}/>", kind, attributes)


class LogAdmin(CommonAdmin):
class LogAdmin(admin.ModelAdmin):

list_display = ("created", "message", "level",)
list_filter = ("level", "created",)
Expand Down
4 changes: 3 additions & 1 deletion src/documents/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ def ready(self):
run_pre_consume_script,
run_post_consume_script,
cleanup_document_deletion,
set_log_entry
set_log_entry,
index_document
)

document_consumption_started.connect(run_pre_consume_script)

document_consumption_finished.connect(classify_document)
document_consumption_finished.connect(index_document)
document_consumption_finished.connect(add_inbox_tags)
document_consumption_finished.connect(set_log_entry)
document_consumption_finished.connect(run_post_consume_script)
Expand Down
1 change: 0 additions & 1 deletion src/documents/consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ def _store(self, text, doc, thumbnail, date):
self._write(document, doc, document.source_path)
self._write(document, thumbnail, document.thumbnail_path)

document.set_filename(document.source_filename)
document.save()

self.log("info", "Completed")
Expand Down
Loading

0 comments on commit 052c168

Please sign in to comment.