77 lines
2.7 KiB
Python
77 lines
2.7 KiB
Python
# fargo - document box
|
|
# Copyright (C) 2016-2019 Entr'ouvert
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify it
|
|
# under the terms of the GNU Affero General Public License as published
|
|
# by the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
from django.contrib import admin
|
|
from django.contrib.auth import get_user_model
|
|
from django.utils.html import format_html
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
from . import models
|
|
|
|
|
|
class UserDocumentAdmin(admin.ModelAdmin):
|
|
list_display = ['user', 'filename', 'thumbnail', 'created', 'origin']
|
|
fields = ['id', 'user', 'filename', 'thumbnail', 'created', 'origin']
|
|
readonly_fields = ['created', 'thumbnail']
|
|
search_fields = ['user__first_name', 'user__last_name', 'user__email', 'filename',
|
|
'origin__label', 'document__content_hash']
|
|
|
|
def thumbnail(self, instance):
|
|
return instance.document.thumbnail_img_tag
|
|
thumbnail.short_description = _('thumbnail')
|
|
|
|
|
|
class DocumentAdmin(admin.ModelAdmin):
|
|
fields = ['content_hash', 'thumbnail', 'users']
|
|
list_display = ['content_hash', 'thumbnail', 'users']
|
|
readonly_fields = ['thumbnail', 'users']
|
|
search_fields = ['content_hash', 'content']
|
|
|
|
def users(self, instance):
|
|
User = get_user_model()
|
|
qs = User.objects.filter(user_documents__document=instance)
|
|
return u', '.join(unicode(u) for u in qs)
|
|
|
|
def thumbnail(self, instance):
|
|
return instance.thumbnail_img_tag
|
|
thumbnail.short_description = _('thumbnail')
|
|
|
|
|
|
class ValidationAdmin(admin.ModelAdmin):
|
|
fields = ['user',
|
|
'content_hash',
|
|
'document_type',
|
|
'start',
|
|
'end',
|
|
'data',
|
|
'creator',
|
|
'created',
|
|
'origin']
|
|
readonly_fields = ['created']
|
|
list_display = ['user', 'display', 'document_type', 'start', 'end', 'creator', 'created',
|
|
'origin']
|
|
|
|
|
|
class OriginAdmin(admin.ModelAdmin):
|
|
fields = ['label', 'slug']
|
|
list_display = ['label', 'slug']
|
|
|
|
|
|
admin.site.register(models.UserDocument, UserDocumentAdmin)
|
|
admin.site.register(models.Document, DocumentAdmin)
|
|
admin.site.register(models.Validation, ValidationAdmin)
|
|
admin.site.register(models.Origin, OriginAdmin)
|