-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1888e89
commit cd7d8ca
Showing
54 changed files
with
2,216 additions
and
188 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -56,3 +56,10 @@ package-lock.json | |
# Virtual environments | ||
venv/ | ||
.venv/ | ||
|
||
# Webpush | ||
/keys/webpush/ | ||
/keys/ | ||
|
||
# Keys | ||
*.pem |
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
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,25 @@ | ||
import base64 | ||
import os | ||
|
||
from cryptography.hazmat.primitives.serialization import Encoding, PublicFormat | ||
from py_vapid import Vapid | ||
|
||
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
os.makedirs(os.path.join(PROJECT_ROOT, "keys", "webpush")) | ||
|
||
# Generate VAPID key pair | ||
vapid = Vapid() | ||
vapid.generate_keys() | ||
|
||
# Get public and private keys for the vapid key pair | ||
vapid.save_public_key(os.path.join(PROJECT_ROOT, "keys", "webpush", "public_key.pem")) | ||
public_key_bytes = vapid.public_key.public_bytes(Encoding.X962, PublicFormat.UncompressedPoint) | ||
|
||
vapid.save_key(os.path.join(PROJECT_ROOT, "keys", "webpush", "private_key.pem")) | ||
|
||
|
||
# Convert the public key to applicationServerKey format | ||
application_server_key = base64.urlsafe_b64encode(public_key_bytes).replace(b"=", b"").decode("utf8") | ||
|
||
with open(os.path.join(PROJECT_ROOT, "keys", "webpush", "ApplicationServerKey.key"), "w", encoding="utf-8") as f: | ||
f.write(application_server_key) |
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
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
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
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
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
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
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
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
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
29 changes: 29 additions & 0 deletions
29
intranet/apps/eighth/management/commands/absence_notify.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,29 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from intranet.apps.eighth.models import EighthSignup | ||
from intranet.apps.eighth.notifications import absence_notification | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Push notify users who have an Eighth Period absence (via Webpush.)" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("--silent", action="store_true", dest="silent", default=False, help="Be silent.") | ||
|
||
parser.add_argument("--pretend", action="store_true", dest="pretend", default=False, help="Pretend, and don't actually do anything.") | ||
|
||
def handle(self, *args, **options): | ||
log = not options["silent"] | ||
|
||
absences = EighthSignup.objects.get_absences().filter(absence_notified=False) | ||
|
||
for signup in absences: | ||
if log: | ||
self.stdout.write(str(signup)) | ||
if not options["pretend"]: | ||
absence_notification(signup) | ||
signup.absence_notified = True | ||
signup.save() | ||
|
||
if log: | ||
self.stdout.write("Done.") |
Oops, something went wrong.