Skip to content

Commit bbe9b8b

Browse files
Add scheduled field to Notification model and update digest email tasks
1 parent 8da7c01 commit bbe9b8b

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

notifications/tasks.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ def send_users_digest_email(dry_run=False):
314314
user_id = group['user_id']
315315
notification_ids = [msg['notification_id'] for msg in group['info']]
316316
if not dry_run:
317+
notifications_qs = Notification.objects.filter(id__in=notification_ids)
318+
notifications_qs.update(scheduled=True)
317319
send_user_email_task.delay(user_id, notification_ids)
318320

319321
@celery_app.task(name='notifications.tasks.send_moderators_digest_email')
@@ -334,6 +336,8 @@ def send_moderators_digest_email(dry_run=False):
334336
provider_content_type_id = group['provider_content_type_id']
335337
notification_ids = [msg['notification_id'] for msg in group['info']]
336338
if not dry_run:
339+
notifications_qs = Notification.objects.filter(id__in=notification_ids)
340+
notifications_qs.update(scheduled=True)
337341
send_moderator_email_task.delay(user_id, notification_ids, provider_content_type_id, provider_id)
338342

339343
def get_moderators_emails(message_freq: str):
@@ -358,6 +362,7 @@ def get_moderators_emails(message_freq: str):
358362
INNER JOIN osf_notificationtype AS nt ON ns.notification_type_id = nt.id
359363
LEFT JOIN osf_guid ON ns.user_id = osf_guid.object_id
360364
WHERE n.sent IS NULL
365+
AND n.scheduled = FALSE
361366
AND ns.message_frequency = %s
362367
AND nt.name IN (%s, %s)
363368
AND nt.name NOT IN (%s, %s, %s)
@@ -401,6 +406,7 @@ def get_users_emails(message_freq):
401406
INNER JOIN osf_notificationtype AS nt ON ns.notification_type_id = nt.id
402407
LEFT JOIN osf_guid ON ns.user_id = osf_guid.object_id
403408
WHERE n.sent IS NULL
409+
AND n.scheduled = FALSE
404410
AND ns.message_frequency = %s
405411
AND nt.name NOT IN (%s, %s, %s, %s, %s)
406412
AND osf_guid.content_type_id = (
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.26 on 2026-06-04 11:52
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('osf', '0039_merge_20260427_1359'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='notification',
15+
name='scheduled',
16+
field=models.BooleanField(default=False),
17+
),
18+
]

osf/models/notification.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class Notification(models.Model):
1818
sent = models.DateTimeField(null=True, blank=True)
1919
created = models.DateTimeField(auto_now_add=True)
2020
fake_sent = models.BooleanField(default=False)
21+
scheduled = models.BooleanField(default=False)
2122

2223
def send(
2324
self,

0 commit comments

Comments
 (0)