-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add pushnotifications for thabloid (#3704)
- Loading branch information
Showing
4 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
website/pushnotifications/migrations/0023_auto_20240529_1952.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 @@ | ||
# Generated by Django 5.0.2 on 2024-05-29 17:03 | ||
|
||
from django.db import migrations | ||
|
||
def forward_func(apps, schema_editor): | ||
category = apps.get_model("pushnotifications", "Category") | ||
category.objects.create(key = "thabloid", | ||
name = "Thabloid", | ||
description="Notification when new Thabloid is uploaded") | ||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("pushnotifications", "0022_remove_device_language"), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(forward_func, migrations.RunPython.noop) | ||
] |
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 |
---|---|---|
@@ -1 +1 @@ | ||
from . import events, newsletters, photos, pizzas # noqa: F401 | ||
from . import events, newsletters, photos, pizzas, thabloid # noqa: F401 |
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 @@ | ||
from django.conf import settings | ||
from django.db.models.signals import post_save | ||
|
||
from members.models import Member | ||
from utils.models.signals import suspendingreceiver | ||
|
||
from ..models import Category, Message | ||
|
||
|
||
@suspendingreceiver( | ||
post_save, | ||
sender="thabloid.Thabloid", | ||
dispatch_uid="schedule_new_thabloid_pushnotification", | ||
) | ||
def send_thabloid_pushnotification(sender, instance, created: bool, **kwargs): | ||
if not created: | ||
return | ||
message = Message.objects.create( | ||
title=f"Thabloid {instance.year}, #{instance.issue}", | ||
body="Tap to view", | ||
url=settings.BASE_URL + instance.get_absolute_url(), | ||
category=Category.objects.get(key=Category.THABLOID), | ||
) | ||
message.users.set(Member.current_members.all()) | ||
message.send() |