first commit
This commit is contained in:
43
monitor/management/commands/setup_notifications.py
Normal file
43
monitor/management/commands/setup_notifications.py
Normal file
@@ -0,0 +1,43 @@
|
||||
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)')
|
||||
)
|
||||
Reference in New Issue
Block a user