first commit
This commit is contained in:
130
monitor/admin.py
Normal file
130
monitor/admin.py
Normal file
@@ -0,0 +1,130 @@
|
||||
from django.contrib import admin
|
||||
from .models import BitcoinPrice, MarketAnalysis, SystemStatus, NotificationPreference, EmailNotification
|
||||
|
||||
|
||||
@admin.register(BitcoinPrice)
|
||||
class BitcoinPriceAdmin(admin.ModelAdmin):
|
||||
list_display = ('timestamp', 'price_usd', 'volume', 'market_cap')
|
||||
list_filter = ('timestamp',)
|
||||
search_fields = ('price_usd',)
|
||||
date_hierarchy = 'timestamp'
|
||||
|
||||
|
||||
@admin.register(MarketAnalysis)
|
||||
class MarketAnalysisAdmin(admin.ModelAdmin):
|
||||
list_display = ('timestamp', 'period', 'status', 'current_price', 'average_price')
|
||||
list_filter = ('period', 'status', 'is_event')
|
||||
search_fields = ('status', 'event_type')
|
||||
date_hierarchy = 'timestamp'
|
||||
|
||||
fieldsets = (
|
||||
('Basic Info', {
|
||||
'fields': ('timestamp', 'period', 'status')
|
||||
}),
|
||||
('Prices', {
|
||||
'fields': ('current_price', 'average_price', 'min_price', 'max_price')
|
||||
}),
|
||||
('Analysis', {
|
||||
'fields': ('threshold_percent', 'lower_threshold', 'upper_threshold')
|
||||
}),
|
||||
('Events', {
|
||||
'fields': ('is_event', 'event_type')
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
@admin.register(SystemStatus)
|
||||
class SystemStatusAdmin(admin.ModelAdmin):
|
||||
list_display = ('timestamp', 'is_healthy', 'is_stale', 'current_price')
|
||||
list_filter = ('is_healthy', 'is_stale')
|
||||
readonly_fields = ('timestamp',)
|
||||
date_hierarchy = 'timestamp'
|
||||
|
||||
fieldsets = (
|
||||
('Status', {
|
||||
'fields': ('timestamp', 'is_healthy', 'is_stale')
|
||||
}),
|
||||
('Updates', {
|
||||
'fields': ('last_hourly_update', 'last_successful_fetch')
|
||||
}),
|
||||
('Current State', {
|
||||
'fields': ('current_price',)
|
||||
}),
|
||||
('Errors', {
|
||||
'fields': ('last_error',),
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
)
|
||||
|
||||
|
||||
@admin.register(NotificationPreference)
|
||||
class NotificationPreferenceAdmin(admin.ModelAdmin):
|
||||
list_display = ('email_address', 'is_active', 'receive_event_alerts',
|
||||
'receive_system_alerts', 'receive_daily_digest', 'created_at')
|
||||
list_filter = ('is_active', 'receive_event_alerts', 'receive_system_alerts',
|
||||
'receive_daily_digest')
|
||||
search_fields = ('email_address',)
|
||||
list_editable = ('is_active', 'receive_event_alerts', 'receive_system_alerts',
|
||||
'receive_daily_digest')
|
||||
|
||||
fieldsets = (
|
||||
('Email Settings', {
|
||||
'fields': ('email_address', 'is_active')
|
||||
}),
|
||||
('Notification Types', {
|
||||
'fields': ('receive_event_alerts', 'receive_system_alerts', 'receive_daily_digest'),
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
('Timestamps', {
|
||||
'fields': ('created_at', 'updated_at'),
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
)
|
||||
|
||||
readonly_fields = ('created_at', 'updated_at')
|
||||
|
||||
|
||||
@admin.register(EmailNotification)
|
||||
class EmailNotificationAdmin(admin.ModelAdmin):
|
||||
list_display = ('recipient', 'subject', 'notification_type', 'status',
|
||||
'sent_at', 'created_at')
|
||||
list_filter = ('notification_type', 'status', 'recipient')
|
||||
search_fields = ('recipient', 'subject', 'error_message')
|
||||
readonly_fields = ('created_at', 'sent_at', 'retry_count')
|
||||
|
||||
fieldsets = (
|
||||
('Basic Info', {
|
||||
'fields': ('recipient', 'subject', 'notification_type', 'status')
|
||||
}),
|
||||
('Content', {
|
||||
'fields': ('content_text', 'content_html'),
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
('Delivery Info', {
|
||||
'fields': ('sent_at', 'retry_count', 'error_message')
|
||||
}),
|
||||
('Timestamps', {
|
||||
'fields': ('created_at',),
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
)
|
||||
|
||||
actions = ['resend_failed_emails']
|
||||
|
||||
def resend_failed_emails(self, request, queryset):
|
||||
"""Resend failed emails."""
|
||||
from monitor.services.email_service import EmailService
|
||||
email_service = EmailService()
|
||||
|
||||
resend_count = 0
|
||||
for email in queryset.filter(status='failed'):
|
||||
try:
|
||||
# Create a copy of the email and send
|
||||
email_service._send_single_email(email, '', {})
|
||||
resend_count += 1
|
||||
except Exception as e:
|
||||
self.message_user(request, f"Failed to resend to {email.recipient}: {e}", level='error')
|
||||
|
||||
self.message_user(request, f"Resent {resend_count} email(s)")
|
||||
|
||||
resend_failed_emails.short_description = "Resend selected failed emails"
|
||||
Reference in New Issue
Block a user