django phase2.3.4.
This commit is contained in:
@@ -145,10 +145,10 @@ class PlanAdmin(admin.ModelAdmin):
|
||||
@admin.register(Account)
|
||||
class AccountAdmin(AccountAdminMixin, admin.ModelAdmin):
|
||||
form = AccountAdminForm
|
||||
list_display = ['name', 'slug', 'owner', 'plan', 'status', 'credits', 'created_at']
|
||||
list_display = ['name', 'slug', 'owner', 'plan', 'status', 'health_indicator', 'credits', 'created_at']
|
||||
list_filter = ['status', 'plan']
|
||||
search_fields = ['name', 'slug']
|
||||
readonly_fields = ['created_at', 'updated_at']
|
||||
readonly_fields = ['created_at', 'updated_at', 'health_indicator', 'health_details']
|
||||
|
||||
def get_queryset(self, request):
|
||||
"""Override to filter by account for non-superusers"""
|
||||
@@ -167,6 +167,137 @@ class AccountAdmin(AccountAdminMixin, admin.ModelAdmin):
|
||||
# If account access fails (e.g., column mismatch), return empty
|
||||
pass
|
||||
return qs.none()
|
||||
|
||||
def health_indicator(self, obj):
|
||||
"""Display health status with visual indicator"""
|
||||
from django.utils.html import format_html
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
|
||||
# Check credits
|
||||
if obj.credits < 10:
|
||||
status = 'critical'
|
||||
icon = '🔴'
|
||||
message = 'Critical: Very low credits'
|
||||
elif obj.credits < 100:
|
||||
status = 'warning'
|
||||
icon = '⚠️'
|
||||
message = 'Warning: Low credits'
|
||||
else:
|
||||
status = 'good'
|
||||
icon = '✅'
|
||||
message = 'Good'
|
||||
|
||||
# Check for recent failed automations
|
||||
try:
|
||||
from igny8_core.business.automation.models import AutomationRun
|
||||
week_ago = timezone.now() - timedelta(days=7)
|
||||
failed_runs = AutomationRun.objects.filter(
|
||||
account=obj,
|
||||
status='failed',
|
||||
created_at__gte=week_ago
|
||||
).count()
|
||||
|
||||
if failed_runs > 5:
|
||||
status = 'critical'
|
||||
icon = '🔴'
|
||||
message = f'Critical: {failed_runs} automation failures'
|
||||
elif failed_runs > 0:
|
||||
if status == 'good':
|
||||
status = 'warning'
|
||||
icon = '⚠️'
|
||||
message = f'Warning: {failed_runs} automation failures'
|
||||
except:
|
||||
pass
|
||||
|
||||
# Check account status
|
||||
if obj.status != 'active':
|
||||
status = 'critical'
|
||||
icon = '🔴'
|
||||
message = f'Critical: Account {obj.status}'
|
||||
|
||||
colors = {
|
||||
'good': '#0bbf87',
|
||||
'warning': '#ff7a00',
|
||||
'critical': '#ef4444'
|
||||
}
|
||||
|
||||
return format_html(
|
||||
'<span style="font-size: 16px;">{}</span> <span style="color: {}; font-weight: 600;">{}</span>',
|
||||
icon, colors[status], message
|
||||
)
|
||||
health_indicator.short_description = 'Health'
|
||||
|
||||
def health_details(self, obj):
|
||||
"""Detailed health information"""
|
||||
from django.utils.html import format_html
|
||||
from django.utils import timezone
|
||||
from datetime import timedelta
|
||||
|
||||
details = []
|
||||
|
||||
# Credits status
|
||||
if obj.credits < 10:
|
||||
details.append(f'🔴 <b>Critical:</b> Only {obj.credits} credits remaining')
|
||||
elif obj.credits < 100:
|
||||
details.append(f'⚠️ <b>Warning:</b> Only {obj.credits} credits remaining')
|
||||
else:
|
||||
details.append(f'✅ <b>Credits:</b> {obj.credits} available')
|
||||
|
||||
# Recent activity
|
||||
try:
|
||||
from igny8_core.modules.writer.models import Content
|
||||
week_ago = timezone.now() - timedelta(days=7)
|
||||
recent_content = Content.objects.filter(
|
||||
site__account=obj,
|
||||
created_at__gte=week_ago
|
||||
).count()
|
||||
details.append(f'📚 <b>Activity:</b> {recent_content} content pieces created this week')
|
||||
except:
|
||||
pass
|
||||
|
||||
# Failed automations
|
||||
try:
|
||||
from igny8_core.business.automation.models import AutomationRun
|
||||
week_ago = timezone.now() - timedelta(days=7)
|
||||
failed_runs = AutomationRun.objects.filter(
|
||||
account=obj,
|
||||
status='failed',
|
||||
created_at__gte=week_ago
|
||||
).count()
|
||||
|
||||
if failed_runs > 0:
|
||||
details.append(f'🔴 <b>Automations:</b> {failed_runs} failures this week')
|
||||
else:
|
||||
details.append(f'✅ <b>Automations:</b> No failures this week')
|
||||
except:
|
||||
pass
|
||||
|
||||
# Failed syncs
|
||||
try:
|
||||
from igny8_core.business.integration.models import SyncEvent
|
||||
today = timezone.now().date()
|
||||
failed_syncs = SyncEvent.objects.filter(
|
||||
site__account=obj,
|
||||
success=False,
|
||||
created_at__date=today
|
||||
).count()
|
||||
|
||||
if failed_syncs > 0:
|
||||
details.append(f'⚠️ <b>Syncs:</b> {failed_syncs} failures today')
|
||||
else:
|
||||
details.append(f'✅ <b>Syncs:</b> No failures today')
|
||||
except:
|
||||
pass
|
||||
|
||||
# Account status
|
||||
if obj.status == 'active':
|
||||
details.append(f'✅ <b>Status:</b> Active')
|
||||
else:
|
||||
details.append(f'🔴 <b>Status:</b> {obj.status.title()}')
|
||||
|
||||
return format_html('<br>'.join(details))
|
||||
health_details.short_description = 'Health Details'
|
||||
|
||||
def has_delete_permission(self, request, obj=None):
|
||||
if obj and getattr(obj, 'slug', '') == 'aws-admin':
|
||||
|
||||
Reference in New Issue
Block a user