Skip to content

Commit

Permalink
feat: added management commands for notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
c0rydoras committed Aug 3, 2023
1 parent 58fbd16 commit 710bf79
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 0 deletions.
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions api/outdated/notifications/management/commands/notify-all.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.core.management.base import BaseCommand

from outdated.notifications.notifier import Notifier
from outdated.outdated.models import Project


class Command(BaseCommand):
help = "Send notifications to every project."

def handle(self, *args, **options):
for project in [p for p in Project.objects.all() if p.maintainers.all()]:
Notifier(project).notify()
11 changes: 11 additions & 0 deletions api/outdated/notifications/management/commands/notify.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from outdated.commands import ProjectCommand
from outdated.notifications.notifier import Notifier


class Command(ProjectCommand):
help = "Send notifications to one specific project."

def _handle(self, project):
if not project.maintainers.all():
raise ValueError("Notify can't be used on projects without maintainers!")
Notifier(project).notify()
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.conf import settings
from django.core.management.base import BaseCommand

from outdated.notifications.models import Notification


class Command(BaseCommand):
help = "Update notifications to match those in settings.py"

def handle(self, *args, **options):
notifications = []
for template, schedule in settings.NOTIFICATIONS:
notifications.append(
Notification.objects.get_or_create(
template=template, schedule=schedule
)[0]
)
[n.delete() for n in Notification.objects.all() if n not in notifications]

0 comments on commit 710bf79

Please sign in to comment.