2019-11-07 10:06:58 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2020-07-09 07:41:02 +00:00
|
|
|
from urllib.parse import urljoin
|
2019-11-07 10:06:58 +00:00
|
|
|
from django.conf import settings
|
|
|
|
from django.utils.translation import ugettext as _
|
|
|
|
|
2020-07-09 07:41:02 +00:00
|
|
|
from common.utils import get_logger
|
2019-11-07 10:06:58 +00:00
|
|
|
from common.tasks import send_mail_async
|
2020-12-29 16:19:59 +00:00
|
|
|
from . import const
|
2019-11-07 10:06:58 +00:00
|
|
|
|
2020-12-29 16:19:59 +00:00
|
|
|
logger = get_logger(__file__)
|
2019-11-07 10:06:58 +00:00
|
|
|
|
2021-01-19 07:44:19 +00:00
|
|
|
EMAIL_TEMPLATE = '''
|
|
|
|
<div>
|
|
|
|
<p>
|
|
|
|
{title}
|
|
|
|
<a href={ticket_detail_url}>
|
|
|
|
<strong>{ticket_detail_url_description}</strong>
|
|
|
|
</a>
|
|
|
|
</p>
|
|
|
|
<div>
|
|
|
|
{body}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
'''
|
|
|
|
|
2019-11-07 10:06:58 +00:00
|
|
|
|
2021-01-18 09:11:30 +00:00
|
|
|
def send_ticket_applied_mail_to_assignees(ticket):
|
2021-08-25 11:02:50 +00:00
|
|
|
assignees = ticket.current_node.first().ticket_assignees.all()
|
|
|
|
if not assignees:
|
2020-12-29 16:19:59 +00:00
|
|
|
logger.debug("Not found assignees, ticket: {}({}), assignees: {}".format(
|
2021-08-25 11:02:50 +00:00
|
|
|
ticket, str(ticket.id), assignees)
|
2020-12-29 16:19:59 +00:00
|
|
|
)
|
2019-11-07 10:06:58 +00:00
|
|
|
return
|
2020-07-09 07:41:02 +00:00
|
|
|
|
2021-01-19 07:44:19 +00:00
|
|
|
ticket_detail_url = urljoin(settings.SITE_URL, const.TICKET_DETAIL_URL.format(id=str(ticket.id)))
|
|
|
|
subject = _('New Ticket - {} ({})').format(ticket.title, ticket.get_type_display())
|
|
|
|
message = EMAIL_TEMPLATE.format(
|
|
|
|
title=_('Your has a new ticket, applicant - {}').format(str(ticket.applicant_display)),
|
|
|
|
ticket_detail_url=ticket_detail_url,
|
|
|
|
ticket_detail_url_description=_('click here to review'),
|
|
|
|
body=ticket.body.replace('\n', '<br/>'),
|
2020-12-29 16:19:59 +00:00
|
|
|
)
|
|
|
|
if settings.DEBUG:
|
|
|
|
logger.debug(message)
|
2021-08-25 11:02:50 +00:00
|
|
|
recipient_list = [i.assignee.email for i in assignees]
|
2019-11-07 10:06:58 +00:00
|
|
|
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|
|
|
|
|
|
|
|
|
2021-08-25 11:02:50 +00:00
|
|
|
def send_ticket_processed_mail_to_applicant(ticket, processor):
|
2020-12-29 16:19:59 +00:00
|
|
|
if not ticket.applicant:
|
|
|
|
logger.error("Not found applicant: {}({})".format(ticket.title, ticket.id))
|
2019-11-07 10:06:58 +00:00
|
|
|
return
|
2021-08-25 11:02:50 +00:00
|
|
|
processor_display = str(processor)
|
2021-01-19 07:44:19 +00:00
|
|
|
ticket_detail_url = urljoin(settings.SITE_URL, const.TICKET_DETAIL_URL.format(id=str(ticket.id)))
|
2021-08-25 11:02:50 +00:00
|
|
|
subject = _('Ticket has processed - {} ({})').format(ticket.title, processor_display)
|
2021-01-19 07:44:19 +00:00
|
|
|
message = EMAIL_TEMPLATE.format(
|
2021-08-25 11:02:50 +00:00
|
|
|
title=_('Your ticket has been processed, processor - {}').format(processor_display),
|
2021-01-19 07:44:19 +00:00
|
|
|
ticket_detail_url=ticket_detail_url,
|
|
|
|
ticket_detail_url_description=_('click here to review'),
|
|
|
|
body=ticket.body.replace('\n', '<br/>'),
|
|
|
|
)
|
2020-12-29 16:19:59 +00:00
|
|
|
if settings.DEBUG:
|
|
|
|
logger.debug(message)
|
2021-08-25 11:02:50 +00:00
|
|
|
recipient_list = [ticket.applicant.email, ]
|
2019-11-07 10:06:58 +00:00
|
|
|
send_mail_async.delay(subject, message, recipient_list, html_message=message)
|