2020-10-20 00:35:27 +02:00
|
|
|
from django.contrib import admin
|
2018-09-23 12:41:28 +01:00
|
|
|
from django.contrib.auth.models import Group, User
|
2018-09-06 10:15:15 +02:00
|
|
|
from django.utils.html import format_html, format_html_join
|
2018-07-04 17:03:59 +02:00
|
|
|
from django.utils.safestring import mark_safe
|
2015-12-20 19:23:33 +00:00
|
|
|
|
2018-09-25 14:47:12 +02:00
|
|
|
from .models import Correspondent, Document, DocumentType, Log, 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
|
|
|
|
2018-09-23 12:41:28 +01:00
|
|
|
list_display = (
|
|
|
|
|
"name",
|
2020-10-28 11:45:11 +01:00
|
|
|
"match",
|
|
|
|
|
"matching_algorithm"
|
2018-09-23 12:41:28 +01:00
|
|
|
)
|
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
|
|
|
|
2018-10-07 16:24:05 +01:00
|
|
|
readonly_fields = ("slug",)
|
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
|
|
|
|
2018-09-25 16:09:33 +02:00
|
|
|
list_display = (
|
|
|
|
|
"name",
|
|
|
|
|
"colour",
|
2020-10-28 11:45:11 +01:00
|
|
|
"match",
|
|
|
|
|
"matching_algorithm"
|
2020-10-21 12:53:14 +02:00
|
|
|
)
|
2020-10-28 11:45:11 +01:00
|
|
|
list_filter = ("colour", "matching_algorithm")
|
|
|
|
|
list_editable = ("colour", "match", "matching_algorithm")
|
2016-01-28 18:37:27 +00:00
|
|
|
|
2018-10-07 16:24:05 +01:00
|
|
|
readonly_fields = ("slug",)
|
|
|
|
|
|
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
|
|
|
|
2020-10-21 12:53:14 +02:00
|
|
|
list_display = (
|
|
|
|
|
"name",
|
2020-10-28 11:45:11 +01:00
|
|
|
"match",
|
|
|
|
|
"matching_algorithm"
|
2020-10-21 12:53:14 +02:00
|
|
|
)
|
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-12-11 12:06:15 +01:00
|
|
|
readonly_fields = ("slug",)
|
|
|
|
|
|
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")
|
2018-10-07 16:26:05 +01:00
|
|
|
readonly_fields = ("added", "file_type", "storage_type",)
|
2020-10-17 01:57:08 +02:00
|
|
|
list_display = ("title", "created", "added", "correspondent",
|
2018-08-24 13:45:15 +02:00
|
|
|
"tags_", "archive_serial_number", "document_type")
|
2018-09-23 12:41:28 +01:00
|
|
|
list_filter = (
|
2018-09-25 14:47:12 +02:00
|
|
|
"document_type",
|
2018-09-23 12:41:28 +01:00
|
|
|
"tags",
|
2020-10-25 23:03:02 +01:00
|
|
|
"correspondent"
|
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
|
|
|
|
2017-01-07 14:57:25 -08:00
|
|
|
ordering = ["-created", "correspondent"]
|
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")
|
2017-03-11 16:37:18 +00:00
|
|
|
created_.short_description = "Created"
|
2016-02-16 09:28:34 +00:00
|
|
|
|
2018-07-04 17:03:59 +02:00
|
|
|
@mark_safe
|
2016-01-23 04:40:35 +00:00
|
|
|
def tags_(self, obj):
|
|
|
|
|
r = ""
|
|
|
|
|
for tag in obj.tags.all():
|
2016-02-27 20:18:50 +00:00
|
|
|
r += self._html_tag(
|
2020-10-17 01:57:08 +02:00
|
|
|
"span",
|
|
|
|
|
tag.slug + ", "
|
2016-01-23 04:40:35 +00:00
|
|
|
)
|
|
|
|
|
return r
|
|
|
|
|
|
2016-02-27 20:18:50 +00:00
|
|
|
@staticmethod
|
|
|
|
|
def _html_tag(kind, inside=None, **kwargs):
|
2018-08-31 00:17:48 +02:00
|
|
|
attributes = format_html_join(' ', '{}="{}"', kwargs.items())
|
2016-02-27 20:18:50 +00:00
|
|
|
|
|
|
|
|
if inside is not None:
|
2018-08-31 00:04:02 +02:00
|
|
|
return format_html("<{kind} {attributes}>{inside}</{kind}>",
|
2018-08-31 00:17:48 +02:00
|
|
|
kind=kind, attributes=attributes, inside=inside)
|
2016-02-27 20:18:50 +00:00
|
|
|
|
2018-08-31 00:04:02 +02:00
|
|
|
return format_html("<{} {}/>", kind, attributes)
|
2016-02-27 20:18:50 +00:00
|
|
|
|
|
|
|
|
|
2020-10-25 23:03:02 +01:00
|
|
|
class LogAdmin(admin.ModelAdmin):
|
2016-02-27 20:18:50 +00:00
|
|
|
|
2016-07-19 14:13:59 +01:00
|
|
|
list_display = ("created", "message", "level",)
|
|
|
|
|
list_filter = ("level", "created",)
|
2016-02-27 20:18:50 +00:00
|
|
|
|
|
|
|
|
|
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)
|
2016-02-27 20:18:50 +00:00
|
|
|
admin.site.register(Log, LogAdmin)
|
|
|
|
|
|
2016-01-28 08:16:29 +00:00
|
|
|
|
|
|
|
|
# Unless we implement multi-user, these default registrations don't make sense.
|
2020-10-20 00:35:27 +02:00
|
|
|
admin.site.unregister(Group)
|
|
|
|
|
admin.site.unregister(User)
|