ArchiveBox/archivebox/api/admin.py

32 lines
1.2 KiB
Python
Raw Normal View History

2024-10-15 00:38:38 +00:00
__package__ = 'archivebox.api'
2024-10-15 00:38:38 +00:00
from signal_webhooks.admin import WebhookAdmin
from signal_webhooks.utils import get_webhook_model
2024-11-19 03:40:05 +00:00
from archivebox.base_models.admin import ABIDModelAdmin
2024-10-15 00:38:38 +00:00
from api.models import APIToken
2024-10-15 00:38:38 +00:00
class APITokenAdmin(ABIDModelAdmin):
list_display = ('created_at', 'abid', 'created_by', 'token_redacted', 'expires')
sort_fields = ('abid', 'created_at', 'created_by', 'expires')
readonly_fields = ('created_at', 'modified_at', 'abid_info')
search_fields = ('id', 'abid', 'created_by__username', 'token')
fields = ('created_by', 'token', 'expires', *readonly_fields)
2024-10-15 00:38:38 +00:00
list_filter = ('created_by',)
ordering = ['-created_at']
list_per_page = 100
2024-10-15 00:38:38 +00:00
class CustomWebhookAdmin(WebhookAdmin, ABIDModelAdmin):
list_display = ('created_at', 'created_by', 'abid', *WebhookAdmin.list_display)
sort_fields = ('created_at', 'created_by', 'abid', 'referenced_model', 'endpoint', 'last_success', 'last_error')
readonly_fields = ('created_at', 'modified_at', 'abid_info', *WebhookAdmin.readonly_fields)
2024-10-15 00:38:38 +00:00
def register_admin(admin_site):
admin_site.register(APIToken, APITokenAdmin)
admin_site.register(get_webhook_model(), CustomWebhookAdmin)