2020-10-20 00:35:27 +02:00
|
|
|
from django.contrib import admin
|
2015-12-20 19:23:33 +00:00
|
|
|
|
2022-03-11 10:55:51 -08:00
|
|
|
from .models import Correspondent
|
|
|
|
|
from .models import Document
|
|
|
|
|
from .models import DocumentType
|
|
|
|
|
from .models import SavedView
|
|
|
|
|
from .models import SavedViewFilterRule
|
2022-05-19 23:42:25 +02:00
|
|
|
from .models import StoragePath
|
2022-03-11 10:55:51 -08:00
|
|
|
from .models import Tag
|
2015-12-20 19:23:33 +00:00
|
|
|
|
|
|
|
|
|
2020-10-25 23:03:02 +01:00
|
|
|
class CorrespondentAdmin(admin.ModelAdmin):
|
2016-03-28 11:11:15 +01:00
|
|
|
|
2022-02-27 15:26:41 +01:00
|
|
|
list_display = ("name", "match", "matching_algorithm")
|
2020-10-28 11:45:11 +01:00
|
|
|
list_filter = ("matching_algorithm",)
|
|
|
|
|
list_editable = ("match", "matching_algorithm")
|
2016-03-28 11:11:15 +01:00
|
|
|
|
|
|
|
|
|
2020-10-25 23:03:02 +01:00
|
|
|
class TagAdmin(admin.ModelAdmin):
|
2016-01-28 18:37:27 +00:00
|
|
|
|
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
|
|
|
|
2018-07-05 12:56:20 +02:00
|
|
|
|
2020-10-25 23:03:02 +01:00
|
|
|
class DocumentTypeAdmin(admin.ModelAdmin):
|
2018-08-24 13:45:15 +02:00
|
|
|
|
2022-02-27 15:26:41 +01:00
|
|
|
list_display = ("name", "match", "matching_algorithm")
|
2020-10-28 11:45:11 +01:00
|
|
|
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
|
|
|
|
2020-10-25 23:03:02 +01:00
|
|
|
class DocumentAdmin(admin.ModelAdmin):
|
2016-02-06 17:27:17 +00:00
|
|
|
|
2018-05-20 17:27:33 +01:00
|
|
|
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
|
|
|
)
|
2017-08-24 20:51:09 +10:00
|
|
|
|
2018-08-26 14:20:07 +02:00
|
|
|
filter_horizontal = ("tags",)
|
2017-08-24 20:51:09 +10:00
|
|
|
|
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"
|
2018-07-04 17:10:56 +02:00
|
|
|
|
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
|
|
|
|
2020-11-08 11:24:57 +01: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:
|
2020-11-08 11:24:57 +01:00
|
|
|
for o in queryset:
|
|
|
|
|
index.remove_document(writer, o)
|
2021-02-15 13:26:36 +01:00
|
|
|
|
2022-05-06 09:04:08 -07:00
|
|
|
super().delete_queryset(request, queryset)
|
2020-11-08 11:24:57 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-11-08 11:24:57 +01:00
|
|
|
index.remove_document_from_index(obj)
|
2022-05-06 09:04:08 -07:00
|
|
|
super().delete_model(request, obj)
|
2020-11-08 11:24:57 +01:00
|
|
|
|
|
|
|
|
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
|
|
|
|
2020-11-08 11:24:57 +01:00
|
|
|
index.add_or_update_document(obj)
|
2022-05-06 09:04:08 -07:00
|
|
|
super().save_model(request, obj, form, change)
|
2020-11-08 11:24:57 +01:00
|
|
|
|
2016-02-27 20:18:50 +00:00
|
|
|
|
2020-12-12 15:46:56 +01:00
|
|
|
class RuleInline(admin.TabularInline):
|
|
|
|
|
model = SavedViewFilterRule
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SavedViewAdmin(admin.ModelAdmin):
|
|
|
|
|
|
2022-12-05 21:02:56 -08:00
|
|
|
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
|
|
|
|
|
|
|
|
|
2022-05-19 23:42:25 +02:00
|
|
|
class StoragePathInline(admin.TabularInline):
|
|
|
|
|
model = StoragePath
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class StoragePathAdmin(admin.ModelAdmin):
|
|
|
|
|
list_display = ("name", "path", "match", "matching_algorithm")
|
|
|
|
|
list_filter = ("path", "matching_algorithm")
|
|
|
|
|
list_editable = ("path", "match", "matching_algorithm")
|
|
|
|
|
|
|
|
|
|
|
2016-03-28 11:11:15 +01:00
|
|
|
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)
|
2022-05-19 23:42:25 +02:00
|
|
|
admin.site.register(StoragePath, StoragePathAdmin)
|