Marwan Alwali 84c1fb798e update
2025-09-08 19:52:52 +03:00

143 lines
5.8 KiB
Python

from django.contrib import admin
from .models import Tenant, AuditLogEntry, SystemConfiguration, SystemNotification, IntegrationLog
@admin.register(Tenant)
class TenantAdmin(admin.ModelAdmin):
"""Admin interface for Tenant model"""
list_display = ['name', 'organization_type', 'is_active', 'created_at']
list_filter = ['organization_type', 'is_active', 'created_at']
search_fields = ['name', 'display_name', 'license_number']
readonly_fields = ['tenant_id', 'created_at', 'updated_at']
fieldsets = (
('Basic Information', {
'fields': ('name', 'display_name', 'description', 'organization_type')
}),
('Contact Information', {
'fields': ('address', 'city', 'state', 'postal_code', 'country', 'phone', 'email', 'website')
}),
('Legal Information', {
'fields': ('license_number', 'tax_id', 'npi_number')
}),
('Configuration', {
'fields': ('is_active', 'subscription_plan', 'max_users', 'features_enabled')
}),
('Metadata', {
'fields': ('tenant_id', 'created_at', 'updated_at'),
'classes': ('collapse',)
})
)
# @admin.register(Department)
# class DepartmentAdmin(admin.ModelAdmin):
# """Admin interface for Department model"""
# list_display = ['name', 'code', 'department_type', 'department_head', 'is_active', 'tenant']
# list_filter = ['department_type', 'is_active', 'tenant', 'created_at']
# search_fields = ['name', 'code', 'description']
# readonly_fields = ['department_id', 'created_at', 'updated_at']
# autocomplete_fields = ['parent_department', 'department_head', 'created_by']
# fieldsets = (
# ('Basic Information', {
# 'fields': ('tenant', 'code', 'name', 'description', 'department_type')
# }),
# ('Organizational Structure', {
# 'fields': ('parent_department', 'department_head')
# }),
# ('Contact Information', {
# 'fields': ('phone', 'extension', 'email')
# }),
# ('Location', {
# 'fields': ('building', 'floor', 'wing', 'room_numbers')
# }),
# ('Operations', {
# 'fields': ('is_active', 'is_24_hour', 'operating_hours')
# }),
# ('Financial', {
# 'fields': ('cost_center_code', 'budget_code')
# }),
# ('Staffing', {
# 'fields': ('authorized_positions', 'current_staff_count')
# }),
# ('Quality & Compliance', {
# 'fields': ('accreditation_required', 'accreditation_body', 'last_inspection_date', 'next_inspection_date')
# }),
# ('Metadata', {
# 'fields': ('department_id', 'created_by', 'created_at', 'updated_at'),
# 'classes': ('collapse',)
# })
# )
#
# def get_queryset(self, request):
# """Filter by tenant if user has tenant"""
# qs = super().get_queryset(request)
# if hasattr(request.user, 'tenant') and request.user.tenant:
# qs = qs.filter(tenant=request.user.tenant)
# return qs
@admin.register(AuditLogEntry)
class AuditLogEntryAdmin(admin.ModelAdmin):
"""Admin interface for AuditLogEntry model"""
list_display = ['action', 'content_type', 'object_id', 'user', 'timestamp', 'tenant']
list_filter = ['action', 'content_type', 'timestamp', 'tenant']
search_fields = ['object_repr', 'user__username', 'user__email']
readonly_fields = ['log_id', 'timestamp']
date_hierarchy = 'timestamp'
def get_queryset(self, request):
"""Filter by tenant if user has tenant"""
qs = super().get_queryset(request)
if hasattr(request.user, 'tenant') and request.user.tenant:
qs = qs.filter(tenant=request.user.tenant)
return qs
@admin.register(SystemConfiguration)
class SystemConfigurationAdmin(admin.ModelAdmin):
"""Admin interface for SystemConfiguration model"""
list_display = ['key', 'category', 'is_active', 'tenant', 'updated_at']
list_filter = ['category', 'is_active', 'tenant', 'updated_at']
search_fields = ['key', 'description']
readonly_fields = ['created_at', 'updated_at']
def get_queryset(self, request):
"""Filter by tenant if user has tenant"""
qs = super().get_queryset(request)
if hasattr(request.user, 'tenant') and request.user.tenant:
qs = qs.filter(tenant=request.user.tenant)
return qs
@admin.register(SystemNotification)
class SystemNotificationAdmin(admin.ModelAdmin):
"""Admin interface for SystemNotification model"""
list_display = ['title', 'notification_type', 'priority', 'is_active', 'tenant', 'created_at']
list_filter = ['notification_type', 'priority', 'is_active', 'tenant', 'created_at']
search_fields = ['title', 'message']
readonly_fields = ['notification_id', 'created_at']
def get_queryset(self, request):
"""Filter by tenant if user has tenant"""
qs = super().get_queryset(request)
if hasattr(request.user, 'tenant') and request.user.tenant:
qs = qs.filter(tenant=request.user.tenant)
return qs
@admin.register(IntegrationLog)
class IntegrationLogAdmin(admin.ModelAdmin):
"""Admin interface for IntegrationLog model"""
list_display = ['integration_type', 'external_system', 'status', 'timestamp', 'tenant']
list_filter = ['integration_type', 'status', 'timestamp', 'tenant']
search_fields = ['external_system', 'correlation_id', 'error_message']
readonly_fields = ['log_id', 'timestamp', 'created_at']
date_hierarchy = 'timestamp'
def get_queryset(self, request):
"""Filter by tenant if user has tenant"""
qs = super().get_queryset(request)
if hasattr(request.user, 'tenant') and request.user.tenant:
qs = qs.filter(tenant=request.user.tenant)
return qs