Files
paperless-ngx/src/documents/admin.py
T

151 lines
4.3 KiB
Python
Raw Normal View History

2020-10-20 00:35:27 +02:00
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 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
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")
2021-02-24 23:52:25 +01:00
list_filter = ("color", "matching_algorithm")
list_editable = ("color", "match", "matching_algorithm")
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",
2022-06-18 08:10:22 +08:00
"original_filename",
2021-02-09 21:00:04 +01:00
)
2020-11-21 23:12:34 +01:00
list_display_links = ("title",)
2022-02-27 15:26:41 +01:00
list_display = ("id", "title", "mime_type", "filename", "archive_filename")
2020-11-21 23:12:34 +01:00
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
)
2018-08-26 14:20:07 +02: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 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
class StoragePathInline(admin.TabularInline):
model = StoragePath
class StoragePathAdmin(GuardedModelAdmin):
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_file_name", "task_name")
search_fields = ("task_name", "task_id", "status")
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",)
2023-09-14 13:32:43 -07:00
class ShareLinksAdmin(GuardedModelAdmin):
list_display = ("created", "expiration", "document")
list_filter = ("created", "expiration", "owner")
list_display_links = ("created",)
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)
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)
2023-09-14 13:32:43 -07:00
admin.site.register(ShareLink, ShareLinksAdmin)