fargo/fargo/oauth2/admin.py

62 lines
2.4 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.utils.translation import ugettext_lazy as _
from .models import OAuth2Client, OAuth2Authorize, OAuth2TempFile
class OAuth2ClientAdmin(admin.ModelAdmin):
fields = ('client_name', 'client_id', 'client_secret', 'redirect_uris')
list_display = ['client_name', 'client_id', 'client_secret', 'redirect_uris']
class OAuth2AuthorizeAdmin(admin.ModelAdmin):
list_display = ['id', 'client_name', 'user_document', 'thumbnail',
'access_token', 'code', 'creation_date']
raw_id_fields = ['user_document']
search_fields = ['client__client_name', 'user_document__user__email',
'user_document__user__first_name',
'user_document__user__last_name',
'user_document__filename',
'user_document__user__contenat_has']
def thumbnail(self, instance):
return instance.user_document.document.thumbnail_img_tag
thumbnail.short_description = _('thumbnail')
def client_name(self, instance):
return instance.client.client_name
class OAuth2TempFileAdmin(admin.ModelAdmin):
list_display = ['uuid', 'client_name', 'filename', 'thumbnail', 'creation_date']
raw_id_fields = ['document']
search_fields = ['filename', 'uuid', 'client__client_name']
def thumbnail(self, instance):
return instance.document.thumbnail_img_tag
thumbnail.short_description = _('thumbnail')
def client_name(self, instance):
return instance.client.client_name
admin.site.register(OAuth2Client, OAuth2ClientAdmin)
admin.site.register(OAuth2Authorize, OAuth2AuthorizeAdmin)
admin.site.register(OAuth2TempFile, OAuth2TempFileAdmin)