jumpserver/apps/tickets/utils.py

55 lines
1.7 KiB
Python
Raw Normal View History

2019-11-07 10:06:58 +00:00
# -*- coding: utf-8 -*-
#
from django.conf import settings
from django.utils.translation import ugettext as _
from common.utils import get_logger, reverse
from common.tasks import send_mail_async
logger = get_logger(__name__)
2019-11-15 10:55:35 +00:00
def send_new_ticket_mail_to_assignees(ticket, assignees):
2019-11-07 10:06:58 +00:00
recipient_list = [user.email for user in assignees]
user = ticket.user
if not recipient_list:
logger.error("Ticket not has assignees: {}".format(ticket.id))
return
subject = '{}: {}'.format(_("New ticket"), ticket.title)
2019-11-15 10:55:35 +00:00
detail_url = reverse('tickets:ticket-detail',
2019-11-07 10:06:58 +00:00
kwargs={'pk': ticket.id}, external=True)
message = _("""
<div>
<p>Your has a new ticket</p>
<div>
2019-11-15 10:55:35 +00:00
{body}
2019-11-07 10:06:58 +00:00
<br/>
<a href={url}>click here to review</a>
</div>
</div>
2019-11-15 10:55:35 +00:00
""").format(body=ticket.body, user=user, url=detail_url)
2019-11-07 10:06:58 +00:00
send_mail_async.delay(subject, message, recipient_list, html_message=message)
2019-11-15 10:55:35 +00:00
def send_ticket_action_mail_to_user(ticket):
2019-11-07 10:06:58 +00:00
if not ticket.user:
logger.error("Ticket not has user: {}".format(ticket.id))
return
user = ticket.user
recipient_list = [user.email]
subject = '{}: {}'.format(_("Ticket has been reply"), ticket.title)
message = _("""
<div>
<p>Your ticket has been replay</p>
<div>
<b>Title:</b> {ticket.title}
<br/>
<b>Assignee:</b> {ticket.assignee_display}
<br/>
<b>Status:</b> {ticket.status_display}
<br/>
</div>
</div>
""").format(ticket=ticket)
send_mail_async.delay(subject, message, recipient_list, html_message=message)