notifications/apps/push_notifications/tasks.py
Ali Asadi a643fee027 FIX(notifications): action_code accepts dots, PushMessage.stats actually updates
Found by an end-to-end run against a live Gotify container:

- action_code / NotificationLink.action_code were SlugField, which rejects
  dots. Every documented action_code (billboard.approved, escrow.timeout,
  ...) is dotted, so any real request using the catalog got a 400 before
  this fix -- only click_url ever worked. Switched both to CharField with
  a validator that keeps slug's charset but allows ".".
- send_push_notification set push_message.state instead of .stats after a
  successful send, so PushMessage.stats stayed stuck at INIT forever
  regardless of delivery outcome. Fixed the attribute name and scoped the
  save with update_fields.

Verified live: POST with a dotted action_code now resolves through
NotificationLink and lands in Gotify with the correct click.url, and the
PushMessage row flips to DONE.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-01 15:55:17 +03:30

22 lines
828 B
Python

from main import celery_app
from utils.clients import gotify
@celery_app.task
def send_push_notification(push_message_uuid):
from .models import PushMessage
push_message = PushMessage.objects.get(uuid=push_message_uuid)
gotify.send_notif(token=push_message.push_user.application_token ,
title=push_message.title,
message=push_message.message,
priority=push_message.priority,
extras=push_message.get_gotify_extras())
push_message.stats = push_message.StateChoices.DONE
push_message.save(update_fields=["stats"])
@celery_app.task
def bulk_push(bulk_push_uuid):
from .models import BulkPushMessage
bulk_push = BulkPushMessage.objects.get(uuid=bulk_push_uuid)
bulk_push.push_to_all(bulk_push.extract_data())