Files
guilan-ace-backend/apps/events/tasks.py
Amirhossein Khalili 3ec28638d1 feat: replace email flows with in-app notifications
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.
2026-09-26 12:23:10 +03:30

53 lines
2.2 KiB
Python

"""Automatic event registration notifications."""
import logging
from celery import shared_task
from apps.events.models import Registration
from apps.notifications.services import notify_user
from apps.users.tasks import send_critical_sms
logger = logging.getLogger(__name__)
@shared_task(bind=True, max_retries=3)
def send_registration_confirmation_notification(self, registration_pk: str):
try:
registration = Registration.objects.select_related("event", "user").get(pk=registration_pk)
notify_user(registration.user_id, {
"type": "event_registration",
"title": f"ثبت‌نام شما برای «{registration.event.title}» تأیید شد",
"message": "ثبت‌نام شما در این رویداد تأیید شده است.",
"level": "success",
"action_url": f"/events/{registration.event.slug}",
"entity_type": "event",
"entity_id": registration.event_id,
"meta": {"ticket_id": str(registration.ticket_id)},
})
return {"sent": True}
except Exception as exc:
logger.error("Failed to notify registration confirmation: %s", exc)
raise self.retry(exc=exc, countdown=60)
@shared_task(bind=True, max_retries=3)
def send_registration_cancellation_notification(self, registration_pk: str):
try:
registration = Registration.objects.select_related("event", "user").get(pk=registration_pk)
notify_user(registration.user_id, {
"type": "event_cancellation",
"title": f"ثبت‌نام شما برای «{registration.event.title}» لغو شد",
"message": "ثبت‌نام شما در این رویداد لغو شد.",
"level": "warning",
"action_url": f"/events/{registration.event.slug}",
"entity_type": "event",
"entity_id": registration.event_id,
})
if registration.user.mobile and registration.user.is_mobile_verified:
send_critical_sms.delay(registration.user.mobile, "event_cancellation", registration.event.title)
return {"sent": True}
except Exception as exc:
logger.error("Failed to notify registration cancellation: %s", exc)
raise self.retry(exc=exc, countdown=60)