-
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
4 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
Empty file.
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 outdated.commands import ProjectCommand | ||
from outdated.notifications.notifier import Notifier | ||
|
||
|
||
class Command(ProjectCommand): | ||
help = "Send notifications to given projects." | ||
|
||
def _handle(self, project): | ||
if not project.maintainers.all(): | ||
self.stdout.write( | ||
f"Skipped {project.name} (no-maintainers)", self.style.WARNING | ||
) | ||
return | ||
elif project.duration_until_outdated is None: | ||
return | ||
|
||
Notifier(project).notify() | ||
self.stdout.write(f"Notified {project}", self.style.SUCCESS) |
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
from datetime import timedelta | ||
|
||
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=timedelta(days=schedule) | ||
)[0] | ||
) | ||
[n.delete() for n in Notification.objects.all() if n not in notifications] |