Add recipient notification detail and filtering, a queued admin composer, and contextual automatic titles. Retire email delivery, obsolete auth routes, newsletter data, and related templates and settings.
32 lines
937 B
Python
32 lines
937 B
Python
import logging
|
|
|
|
from celery import shared_task
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from apps.notifications.services import RedisNotificationStore, notify_user
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@shared_task
|
|
def cleanup_notification_retention():
|
|
removed = RedisNotificationStore.cleanup_expired()
|
|
logger.info("Cleaned up %s expired notifications", removed)
|
|
return removed
|
|
|
|
|
|
@shared_task
|
|
def send_manual_notification(user_ids: list[int], title: str, digest: str, body_markdown: str | None = None):
|
|
users = get_user_model().objects.filter(pk__in=user_ids, is_active=True, is_deleted=False)
|
|
sent = 0
|
|
for user_id in users.values_list("pk", flat=True).iterator():
|
|
notify_user(user_id, {
|
|
"type": "manual",
|
|
"title": title,
|
|
"message": digest,
|
|
"body_markdown": body_markdown,
|
|
"level": "info",
|
|
})
|
|
sent += 1
|
|
return sent
|