44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from django.core.management.base import BaseCommand
|
|
from monitor.models import NotificationPreference
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Setup initial notification preferences'
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument(
|
|
'--emails',
|
|
nargs='+',
|
|
type=str,
|
|
default=['ali.c.zeybek@gmail.com', 'alican@alicanzeybek.xyz'],
|
|
help='Email addresses to setup notifications for'
|
|
)
|
|
|
|
def handle(self, *args, **options):
|
|
emails = options['emails']
|
|
|
|
for email in emails:
|
|
# Check if preference already exists
|
|
pref, created = NotificationPreference.objects.get_or_create(
|
|
email_address=email,
|
|
defaults={
|
|
'receive_event_alerts': True,
|
|
'receive_system_alerts': True,
|
|
'receive_daily_digest': True,
|
|
'is_active': True,
|
|
}
|
|
)
|
|
|
|
if created:
|
|
self.stdout.write(
|
|
self.style.SUCCESS(f'Created notification preference for {email}')
|
|
)
|
|
else:
|
|
self.stdout.write(
|
|
self.style.WARNING(f'Notification preference for {email} already exists')
|
|
)
|
|
|
|
self.stdout.write(
|
|
self.style.SUCCESS(f'Setup complete for {len(emails)} email(s)')
|
|
)
|