You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
2.5 KiB
64 lines
2.5 KiB
from django.contrib import admin
|
|
from django.utils import timezone
|
|
from django.utils.html import format_html
|
|
from django.utils.translation import gettext_lazy as _
|
|
from unfold.admin import ModelAdmin, StackedInline
|
|
from unfold.decorators import display, action
|
|
|
|
from apps.account.models.verification import VerificationDocument
|
|
from utils.admin import project_admin_site
|
|
|
|
|
|
class VerificationDocumentInline(StackedInline):
|
|
model = VerificationDocument
|
|
extra = 0
|
|
fields = ('document_type', 'title', 'document_file', 'status', 'admin_notes', 'reviewed_by', 'uploaded_at')
|
|
readonly_fields = ('uploaded_at',)
|
|
|
|
|
|
@admin.register(VerificationDocument, site=project_admin_site)
|
|
class VerificationDocumentAdmin(ModelAdmin):
|
|
list_display = ('id', 'user_display', 'document_type', 'status_badge', 'uploaded_at', 'reviewed_by', 'reviewed_at')
|
|
list_filter = ('status', 'document_type', 'uploaded_at')
|
|
search_fields = ('user__email', 'user__fullname', 'title', 'admin_notes')
|
|
readonly_fields = ('uploaded_at', 'reviewed_at')
|
|
actions = ['approve_documents', 'reject_documents']
|
|
|
|
fieldsets = (
|
|
(_('Document Information'), {
|
|
'fields': ('user', 'document_type', 'title', 'document_file')
|
|
}),
|
|
(_('Review Status'), {
|
|
'fields': ('status', 'admin_notes', 'reviewed_by', 'reviewed_at', 'uploaded_at')
|
|
}),
|
|
)
|
|
|
|
@display(description=_('User'))
|
|
def user_display(self, obj):
|
|
return obj.user.fullname or obj.user.email
|
|
|
|
@display(description=_('Status'), label={
|
|
VerificationDocument.Status.VERIFIED: "success",
|
|
VerificationDocument.Status.PENDING: "warning",
|
|
VerificationDocument.Status.REJECTED: "danger",
|
|
})
|
|
def status_badge(self, obj):
|
|
return obj.get_status_display()
|
|
|
|
@action(description=_('Approve selected verification documents'))
|
|
def approve_documents(self, request, queryset):
|
|
queryset.update(
|
|
status=VerificationDocument.Status.VERIFIED,
|
|
reviewed_by=request.user,
|
|
reviewed_at=timezone.now()
|
|
)
|
|
self.message_user(request, _("Selected documents have been approved."))
|
|
|
|
@action(description=_('Reject selected verification documents'))
|
|
def reject_documents(self, request, queryset):
|
|
queryset.update(
|
|
status=VerificationDocument.Status.REJECTED,
|
|
reviewed_by=request.user,
|
|
reviewed_at=timezone.now()
|
|
)
|
|
self.message_user(request, _("Selected documents have been rejected."))
|