Skip to content

Commit

Permalink
add pushnotifications for thabloid (#3704)
Browse files Browse the repository at this point in the history
  • Loading branch information
Noah-marc authored May 29, 2024
1 parent 7f3c857 commit f9600da
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 1 deletion.
18 changes: 18 additions & 0 deletions website/pushnotifications/migrations/0023_auto_20240529_1952.py
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)
]
1 change: 1 addition & 0 deletions website/pushnotifications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Category(models.Model):
PARTNER = "partner"
PHOTO = "photo"
BOARD = "board"
THABLOID = "thabloid"

key = models.CharField(max_length=16, primary_key=True)

Expand Down
2 changes: 1 addition & 1 deletion website/pushnotifications/signals/__init__.py
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
25 changes: 25 additions & 0 deletions website/pushnotifications/signals/thabloid.py
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()

0 comments on commit f9600da

Please sign in to comment.