From 9f02c41c9c2fbd9f8e975e8b10384e398fee96e6 Mon Sep 17 00:00:00 2001 From: jedi Date: Sat, 4 May 2024 01:03:51 +0200 Subject: [PATCH] stash --- core/notifications/dispatch.py | 5 +++-- core/notifications/templates.py | 11 ++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/notifications/dispatch.py b/core/notifications/dispatch.py index e83c1e4..b77c8ea 100644 --- a/core/notifications/dispatch.py +++ b/core/notifications/dispatch.py @@ -6,7 +6,7 @@ from urllib.parse import quote as urlencode from core.settings import TELEGRAM_BOT_TOKEN, TELEGRAM_GROUP_CHAT_ID from mail.protocol import send_smtp, make_notification from notifications.models import UserNotificationChannel -from notifications.templates import render_notification_new_ticket, render_notification_reply_ticket +from notifications.templates import render_notification_new_ticket_async, render_notification_reply_ticket_async from tickets.models import IssueThread @@ -64,7 +64,8 @@ class NotificationDispatcher: print("Error: Invalid message format") async def dispatch(self, ticket, event_id, new): - message = render_notification_new_ticket(ticket) if new else await render_notification_reply_ticket(ticket) + message = await render_notification_new_ticket_async( + ticket) if new else await render_notification_reply_ticket_async(ticket) print("Dispatching message:", message, "with event_id:", event_id) targets = await self.get_notification_targets() # await telegram_notify(message, TELEGRAM_GROUP_CHAT_ID) diff --git a/core/notifications/templates.py b/core/notifications/templates.py index 1dd7aea..e658c2e 100644 --- a/core/notifications/templates.py +++ b/core/notifications/templates.py @@ -37,22 +37,27 @@ def render_template(template, **kwargs): return None -@database_sync_to_async def render_auto_reply(ticket): eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded return render_template('auto_reply', ticket_name=ticket.name, ticket_uuid=ticket.short_uuid(), ticket_id=ticket.id, event_slug=eventslug, ticket_url=ticket_url(ticket)) -@database_sync_to_async def render_notification_new_ticket(ticket): eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded return render_template('new_issue_notification', ticket_name=ticket.name, ticket_uuid=ticket.short_uuid(), ticket_id=ticket.id, event_slug=eventslug, ticket_url=ticket_url(ticket)) -@database_sync_to_async +async def render_notification_new_ticket_async(ticket): + return await database_sync_to_async(render_notification_new_ticket)(ticket) + + def render_notification_reply_ticket(ticket): eventslug = ticket.event.slug if ticket.event else "37C3" # TODO 37C3 should not be hardcoded return render_template('reply_issue_notification', ticket_name=ticket.name, ticket_uuid=ticket.short_uuid(), ticket_id=ticket.id, event_slug=eventslug, ticket_url=ticket_url(ticket)) + + +async def render_notification_reply_ticket_async(ticket): + return await database_sync_to_async(render_notification_reply_ticket)(ticket)