paperless-ngx/src/documents/admin.py

215 lines
6.4 KiB
Python
Raw Normal View History

from django.conf import settings
from django.contrib import admin
from guardian.admin import GuardedModelAdmin
2015-12-20 19:23:33 +00:00
from documents.models import Correspondent
from documents.models import CustomField
from documents.models import CustomFieldInstance
from documents.models import Document
from documents.models import DocumentType
from documents.models import Note
from documents.models import PaperlessTask
from documents.models import SavedView
from documents.models import SavedViewFilterRule
from documents.models import ShareLink
from documents.models import StoragePath
from documents.models import Tag
2015-12-20 19:23:33 +00:00
if settings.AUDIT_LOG_ENABLED:
from auditlog.admin import LogEntryAdmin
from auditlog.models import LogEntry
2015-12-20 19:23:33 +00:00
class CorrespondentAdmin(GuardedModelAdmin):
2022-02-27 15:26:41 +01:00
list_display = ("name", "match", "matching_algorithm")
list_filter = ("matching_algorithm",)
list_editable = ("match", "matching_algorithm")
class TagAdmin(GuardedModelAdmin):
2022-02-27 15:26:41 +01:00
list_display = ("name", "color", "match", "matching_algorithm")
list_filter = ("matching_algorithm",)
2021-02-24 23:52:25 +01:00
list_editable = ("color", "match", "matching_algorithm")
search_fields = ("color", "name")
2016-01-28 18:37:27 +00:00
class DocumentTypeAdmin(GuardedModelAdmin):
2022-02-27 15:26:41 +01:00
list_display = ("name", "match", "matching_algorithm")
list_filter = ("matching_algorithm",)
list_editable = ("match", "matching_algorithm")
2018-08-24 13:45:15 +02:00
2018-09-13 14:15:16 +02:00
class DocumentAdmin(GuardedModelAdmin):
search_fields = ("correspondent__name", "title", "content", "tags__name")
2020-12-07 21:51:00 +01:00
readonly_fields = (
"added",
"modified",
"mime_type",
"storage_type",
2021-02-09 21:00:04 +01:00
"filename",
"checksum",
"archive_filename",
2022-02-27 15:26:41 +01:00
"archive_checksum",
"original_filename",
"deleted_at",
2021-02-09 21:00:04 +01:00
)
list_display_links = ("title",)
2022-02-27 15:26:41 +01:00
list_display = ("id", "title", "mime_type", "filename", "archive_filename")
2018-09-23 12:41:28 +01:00
list_filter = (
2021-02-10 18:55:39 +01:00
("mime_type"),
("archive_serial_number", admin.EmptyFieldListFilter),
("archive_filename", admin.EmptyFieldListFilter),
2018-09-23 12:41:28 +01:00
)
filter_horizontal = ("tags",)
2021-02-10 21:34:50 +01:00
ordering = ["-id"]
2015-12-20 19:23:33 +00:00
2018-09-23 12:41:28 +01:00
date_hierarchy = "created"
2017-03-05 12:15:18 +00:00
def has_add_permission(self, request):
return False
2016-02-16 09:28:34 +00:00
def created_(self, obj):
return obj.created.date().strftime("%Y-%m-%d")
2022-02-27 15:26:41 +01:00
2017-03-11 16:37:18 +00:00
created_.short_description = "Created"
2016-02-16 09:28:34 +00:00
def get_queryset(self, request): # pragma: no cover
"""
Include trashed documents
"""
return Document.global_objects.all()
def delete_queryset(self, request, queryset):
2021-02-15 13:26:36 +01:00
from documents import index
with index.open_index_writer() as writer:
for o in queryset:
index.remove_document(writer, o)
2021-02-15 13:26:36 +01:00
super().delete_queryset(request, queryset)
def delete_model(self, request, obj):
2021-02-15 13:26:36 +01:00
from documents import index
2022-02-27 15:26:41 +01:00
index.remove_document_from_index(obj)
super().delete_model(request, obj)
def save_model(self, request, obj, form, change):
2021-02-15 13:26:36 +01:00
from documents import index
2022-02-27 15:26:41 +01:00
index.add_or_update_document(obj)
super().save_model(request, obj, form, change)
2016-02-27 20:18:50 +00:00
2020-12-12 15:46:56 +01:00
class RuleInline(admin.TabularInline):
model = SavedViewFilterRule
class SavedViewAdmin(GuardedModelAdmin):
list_display = ("name", "owner")
2020-12-12 15:46:56 +01:00
2022-02-27 15:26:41 +01:00
inlines = [RuleInline]
2020-12-12 15:46:56 +01:00
def get_queryset(self, request): # pragma: no cover
return super().get_queryset(request).select_related("owner")
2020-12-12 15:46:56 +01:00
Feature: Dynamic document storage pathes (#916) * Added devcontainer * Add feature storage pathes * Exclude tests and add versioning * Check escaping * Check escaping * Check quoting * Echo * Escape * Escape : * Double escape \ * Escaping * Remove if * Escape colon * Missing \ * Esacpe : * Escape all * test * Remove sed * Fix exclude * Remove SED command * Add LD_LIBRARY_PATH * Adjusted to v1.7 * Updated test-cases * Remove devcontainer * Removed internal build-file * Run pre-commit * Corrected flak8 error * Adjusted to v1.7 * Updated test-cases * Corrected flak8 error * Adjusted to new plural translations * Small adjustments due to code-review backend * Adjusted line-break * Removed PAPERLESS prefix from settings variables * Corrected style change due to search+replace * First documentation draft * Revert changes to Pipfile * Add sphinx-autobuild with keep-outdated * Revert merge error that results in wrong storage path is evaluated * Adjust styles of generated files ... * Adds additional testing to cover dynamic storage path functionality * Remove unnecessary condition * Add hint to edit storage path dialog * Correct spelling of pathes to paths * Minor documentation tweaks * Minor typo * improving wrapping of filter editor buttons with new storage path button * Update .gitignore * Fix select border radius in non input-groups * Better storage path edit hint * Add note to edit storage path dialog re document_renamer * Add note to bulk edit storage path re document_renamer * Rename FILTER_STORAGE_DIRECTORY to PATH * Fix broken filter rule parsing * Show default storage if unspecified * Remove note re storage path on bulk edit * Add basic validation of filename variables Co-authored-by: Markus Kling <markus@markus-kling.net> Co-authored-by: Trenton Holmes <holmes.trenton@gmail.com> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Co-authored-by: Quinn Casey <quinn@quinncasey.com>
2022-05-19 23:42:25 +02:00
class StoragePathInline(admin.TabularInline):
model = StoragePath
class StoragePathAdmin(GuardedModelAdmin):
Feature: Dynamic document storage pathes (#916) * Added devcontainer * Add feature storage pathes * Exclude tests and add versioning * Check escaping * Check escaping * Check quoting * Echo * Escape * Escape : * Double escape \ * Escaping * Remove if * Escape colon * Missing \ * Esacpe : * Escape all * test * Remove sed * Fix exclude * Remove SED command * Add LD_LIBRARY_PATH * Adjusted to v1.7 * Updated test-cases * Remove devcontainer * Removed internal build-file * Run pre-commit * Corrected flak8 error * Adjusted to v1.7 * Updated test-cases * Corrected flak8 error * Adjusted to new plural translations * Small adjustments due to code-review backend * Adjusted line-break * Removed PAPERLESS prefix from settings variables * Corrected style change due to search+replace * First documentation draft * Revert changes to Pipfile * Add sphinx-autobuild with keep-outdated * Revert merge error that results in wrong storage path is evaluated * Adjust styles of generated files ... * Adds additional testing to cover dynamic storage path functionality * Remove unnecessary condition * Add hint to edit storage path dialog * Correct spelling of pathes to paths * Minor documentation tweaks * Minor typo * improving wrapping of filter editor buttons with new storage path button * Update .gitignore * Fix select border radius in non input-groups * Better storage path edit hint * Add note to edit storage path dialog re document_renamer * Add note to bulk edit storage path re document_renamer * Rename FILTER_STORAGE_DIRECTORY to PATH * Fix broken filter rule parsing * Show default storage if unspecified * Remove note re storage path on bulk edit * Add basic validation of filename variables Co-authored-by: Markus Kling <markus@markus-kling.net> Co-authored-by: Trenton Holmes <holmes.trenton@gmail.com> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Co-authored-by: Quinn Casey <quinn@quinncasey.com>
2022-05-19 23:42:25 +02:00
list_display = ("name", "path", "match", "matching_algorithm")
list_filter = ("path", "matching_algorithm")
list_editable = ("path", "match", "matching_algorithm")
2022-12-14 09:07:25 -08:00
class TaskAdmin(admin.ModelAdmin):
list_display = ("task_id", "task_file_name", "task_name", "date_done", "status")
list_filter = ("status", "date_done", "task_name")
search_fields = ("task_name", "task_id", "status", "task_file_name")
2022-12-14 09:07:25 -08:00
readonly_fields = (
"task_id",
"task_file_name",
"task_name",
"status",
"date_created",
"date_started",
"date_done",
"result",
)
2023-03-17 16:36:08 -07:00
class NotesAdmin(GuardedModelAdmin):
list_display = ("user", "created", "note", "document")
list_filter = ("created", "user")
list_display_links = ("created",)
raw_id_fields = ("document",)
search_fields = ("document__title",)
def get_queryset(self, request): # pragma: no cover
return (
super()
.get_queryset(request)
.select_related("user", "document__correspondent")
)
2023-03-17 16:36:08 -07:00
class ShareLinksAdmin(GuardedModelAdmin):
list_display = ("created", "expiration", "document")
list_filter = ("created", "expiration", "owner")
list_display_links = ("created",)
raw_id_fields = ("document",)
def get_queryset(self, request): # pragma: no cover
return super().get_queryset(request).select_related("document__correspondent")
class CustomFieldsAdmin(GuardedModelAdmin):
fields = ("name", "created", "data_type")
readonly_fields = ("created", "data_type")
list_display = ("name", "created", "data_type")
list_filter = ("created", "data_type")
class CustomFieldInstancesAdmin(GuardedModelAdmin):
fields = ("field", "document", "created", "value")
readonly_fields = ("field", "document", "created", "value")
list_display = ("field", "document", "value", "created")
search_fields = ("document__title",)
list_filter = ("created", "field")
def get_queryset(self, request): # pragma: no cover
return (
super()
.get_queryset(request)
.select_related("field", "document__correspondent")
)
admin.site.register(Correspondent, CorrespondentAdmin)
2016-01-28 18:37:27 +00:00
admin.site.register(Tag, TagAdmin)
2018-08-24 13:45:15 +02:00
admin.site.register(DocumentType, DocumentTypeAdmin)
2015-12-20 19:23:33 +00:00
admin.site.register(Document, DocumentAdmin)
2020-12-12 15:46:56 +01:00
admin.site.register(SavedView, SavedViewAdmin)
Feature: Dynamic document storage pathes (#916) * Added devcontainer * Add feature storage pathes * Exclude tests and add versioning * Check escaping * Check escaping * Check quoting * Echo * Escape * Escape : * Double escape \ * Escaping * Remove if * Escape colon * Missing \ * Esacpe : * Escape all * test * Remove sed * Fix exclude * Remove SED command * Add LD_LIBRARY_PATH * Adjusted to v1.7 * Updated test-cases * Remove devcontainer * Removed internal build-file * Run pre-commit * Corrected flak8 error * Adjusted to v1.7 * Updated test-cases * Corrected flak8 error * Adjusted to new plural translations * Small adjustments due to code-review backend * Adjusted line-break * Removed PAPERLESS prefix from settings variables * Corrected style change due to search+replace * First documentation draft * Revert changes to Pipfile * Add sphinx-autobuild with keep-outdated * Revert merge error that results in wrong storage path is evaluated * Adjust styles of generated files ... * Adds additional testing to cover dynamic storage path functionality * Remove unnecessary condition * Add hint to edit storage path dialog * Correct spelling of pathes to paths * Minor documentation tweaks * Minor typo * improving wrapping of filter editor buttons with new storage path button * Update .gitignore * Fix select border radius in non input-groups * Better storage path edit hint * Add note to edit storage path dialog re document_renamer * Add note to bulk edit storage path re document_renamer * Rename FILTER_STORAGE_DIRECTORY to PATH * Fix broken filter rule parsing * Show default storage if unspecified * Remove note re storage path on bulk edit * Add basic validation of filename variables Co-authored-by: Markus Kling <markus@markus-kling.net> Co-authored-by: Trenton Holmes <holmes.trenton@gmail.com> Co-authored-by: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Co-authored-by: Quinn Casey <quinn@quinncasey.com>
2022-05-19 23:42:25 +02:00
admin.site.register(StoragePath, StoragePathAdmin)
2022-12-14 09:07:25 -08:00
admin.site.register(PaperlessTask, TaskAdmin)
2023-03-17 16:36:08 -07:00
admin.site.register(Note, NotesAdmin)
admin.site.register(ShareLink, ShareLinksAdmin)
admin.site.register(CustomField, CustomFieldsAdmin)
admin.site.register(CustomFieldInstance, CustomFieldInstancesAdmin)
if settings.AUDIT_LOG_ENABLED:
class LogEntryAUDIT(LogEntryAdmin):
def has_delete_permission(self, request, obj=None):
return False
admin.site.unregister(LogEntry)
admin.site.register(LogEntry, LogEntryAUDIT)