-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added management commands for notifications
- Loading branch information
Showing
5 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
12 changes: 12 additions & 0 deletions
12
api/outdated/notifications/management/commands/notify-all.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
18 changes: 18 additions & 0 deletions
18
api/outdated/notifications/management/commands/update-notifications.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |