You've already forked hotpocket
BTHLABS-66: Prepping for public release: Take four
Apple gonna Apple... ;)
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
from .access_token import AccessToken # noqa: F401
|
||||
from .account import AccountAdmin # noqa: F401
|
||||
from .auth_key import AuthKey # noqa: F401
|
||||
|
||||
@@ -2,16 +2,41 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from hotpocket_backend.apps.accounts.models import AccessToken
|
||||
|
||||
|
||||
class AccessTokenAdmin(admin.ModelAdmin):
|
||||
list_display = ('pk', 'account_uuid', 'origin', 'created_at', 'is_active')
|
||||
list_display = (
|
||||
'pk', 'account_uuid', 'origin', 'created_at', 'render_is_active',
|
||||
)
|
||||
search_fields = ('pk', 'account_uuid', 'key', 'origin')
|
||||
readonly_fields = (
|
||||
'pk',
|
||||
'account_uuid',
|
||||
'key',
|
||||
'origin',
|
||||
'meta',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
)
|
||||
ordering = ['-created_at']
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return request.user.is_superuser
|
||||
|
||||
@admin.display(
|
||||
description=_('Is Active?'), boolean=True, ordering='-deleted_at',
|
||||
)
|
||||
def render_is_active(self, obj: AccessToken | None = None) -> bool | None:
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
return obj.is_active
|
||||
|
||||
|
||||
admin.site.register(AccessToken, AccessTokenAdmin)
|
||||
|
||||
@@ -3,15 +3,26 @@ from __future__ import annotations
|
||||
|
||||
from django.contrib import admin
|
||||
from django.contrib.auth.admin import UserAdmin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from hotpocket_backend.apps.accounts.models import Account
|
||||
|
||||
|
||||
class AccountAdmin(UserAdmin):
|
||||
list_display = (*UserAdmin.list_display, 'is_active')
|
||||
list_display = (*UserAdmin.list_display, 'render_is_active')
|
||||
ordering = ['username']
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return request.user.is_superuser
|
||||
|
||||
@admin.display(
|
||||
description=_('Is Active?'), boolean=True, ordering='-is_active',
|
||||
)
|
||||
def render_is_active(self, obj: Account | None = None) -> bool | None:
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
return obj.is_active
|
||||
|
||||
|
||||
admin.site.register(Account, AccountAdmin)
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
from django.contrib import admin
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from hotpocket_backend.apps.accounts.models import AuthKey
|
||||
|
||||
|
||||
class AuthKeyAdmin(admin.ModelAdmin):
|
||||
list_display = (
|
||||
'pk', 'account_uuid', 'key', 'created_at', 'consumed_at', 'render_is_active',
|
||||
)
|
||||
search_fields = ('pk', 'account_uuid', 'key')
|
||||
readonly_fields = (
|
||||
'pk',
|
||||
'account_uuid',
|
||||
'key',
|
||||
'consumed_at',
|
||||
'created_at',
|
||||
'deleted_at',
|
||||
)
|
||||
ordering = ['-created_at']
|
||||
|
||||
def has_change_permission(self, request, obj=None):
|
||||
return False
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
return request.user.is_superuser
|
||||
|
||||
@admin.display(
|
||||
description=_('Is Active?'), boolean=True, ordering='-deleted_at',
|
||||
)
|
||||
def render_is_active(self, obj: AuthKey | None = None) -> bool | None:
|
||||
if obj is None:
|
||||
return None
|
||||
|
||||
return obj.is_active
|
||||
|
||||
|
||||
admin.site.register(AuthKey, AuthKeyAdmin)
|
||||
Reference in New Issue
Block a user