2021-09-13 10:50:29 +00:00
|
|
|
from urllib.parse import urljoin
|
|
|
|
|
|
|
|
from django.conf import settings
|
2021-10-20 11:45:37 +00:00
|
|
|
from django.template.loader import render_to_string
|
2021-10-21 12:03:05 +00:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
2021-09-13 10:50:29 +00:00
|
|
|
|
|
|
|
from . import const
|
|
|
|
from notifications.notifications import UserMessage
|
|
|
|
from common.utils import get_logger
|
2021-10-20 11:45:37 +00:00
|
|
|
from .models import Ticket
|
2021-09-13 10:50:29 +00:00
|
|
|
|
|
|
|
logger = get_logger(__file__)
|
|
|
|
|
|
|
|
|
|
|
|
class BaseTicketMessage(UserMessage):
|
2021-10-20 11:45:37 +00:00
|
|
|
title: ''
|
|
|
|
ticket: Ticket
|
|
|
|
content_title: str
|
2021-09-13 10:50:29 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def ticket_detail_url(self):
|
2021-10-22 12:06:16 +00:00
|
|
|
tp = self.ticket.type
|
2021-09-13 10:50:29 +00:00
|
|
|
return urljoin(settings.SITE_URL, const.TICKET_DETAIL_URL.format(id=str(self.ticket.id)))
|
|
|
|
|
2021-10-21 12:03:05 +00:00
|
|
|
@property
|
|
|
|
def content_title(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
|
|
|
@property
|
|
|
|
def subject(self):
|
|
|
|
raise NotImplementedError
|
|
|
|
|
2021-09-13 10:50:29 +00:00
|
|
|
def get_html_msg(self) -> dict:
|
2021-10-20 11:45:37 +00:00
|
|
|
context = dict(
|
2021-09-13 10:50:29 +00:00
|
|
|
title=self.content_title,
|
|
|
|
ticket_detail_url=self.ticket_detail_url,
|
|
|
|
body=self.ticket.body.replace('\n', '<br/>'),
|
|
|
|
)
|
2021-10-20 11:45:37 +00:00
|
|
|
message = render_to_string('tickets/_msg_ticket.html', context)
|
2021-09-13 10:50:29 +00:00
|
|
|
return {
|
|
|
|
'subject': self.subject,
|
|
|
|
'message': message
|
|
|
|
}
|
|
|
|
|
2021-10-20 11:45:37 +00:00
|
|
|
@classmethod
|
|
|
|
def gen_test_msg(cls):
|
2021-10-20 12:25:21 +00:00
|
|
|
return None
|
2021-10-20 11:45:37 +00:00
|
|
|
|
2021-09-13 10:50:29 +00:00
|
|
|
|
|
|
|
class TicketAppliedToAssignee(BaseTicketMessage):
|
|
|
|
def __init__(self, user, ticket):
|
|
|
|
self.ticket = ticket
|
|
|
|
super().__init__(user)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def content_title(self):
|
2021-10-20 11:45:37 +00:00
|
|
|
return _('Your has a new ticket, applicant - {}').format(
|
|
|
|
str(self.ticket.applicant_display)
|
|
|
|
)
|
|
|
|
|
2021-10-21 12:03:05 +00:00
|
|
|
@property
|
|
|
|
def subject(self):
|
|
|
|
title = _('New Ticket - {} ({})').format(
|
|
|
|
self.ticket.title, self.ticket.get_type_display()
|
|
|
|
)
|
|
|
|
return title
|
|
|
|
|
2021-10-20 11:45:37 +00:00
|
|
|
@classmethod
|
|
|
|
def gen_test_msg(cls):
|
|
|
|
from .models import Ticket
|
|
|
|
from users.models import User
|
|
|
|
ticket = Ticket.objects.first()
|
|
|
|
user = User.objects.first()
|
|
|
|
return cls(user, ticket)
|
2021-09-13 10:50:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TicketProcessedToApplicant(BaseTicketMessage):
|
|
|
|
def __init__(self, user, ticket, processor):
|
|
|
|
self.ticket = ticket
|
|
|
|
self.processor = processor
|
|
|
|
super().__init__(user)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def content_title(self):
|
|
|
|
return _('Your ticket has been processed, processor - {}').format(str(self.processor))
|
2021-10-20 11:45:37 +00:00
|
|
|
|
2021-10-21 12:03:05 +00:00
|
|
|
@property
|
|
|
|
def subject(self):
|
|
|
|
title = _('Ticket has processed - {} ({})').format(
|
|
|
|
self.ticket.title, self.ticket.get_type_display()
|
|
|
|
)
|
|
|
|
return title
|
|
|
|
|
2021-10-20 11:45:37 +00:00
|
|
|
@classmethod
|
|
|
|
def gen_test_msg(cls):
|
|
|
|
from .models import Ticket
|
|
|
|
from users.models import User
|
|
|
|
ticket = Ticket.objects.first()
|
|
|
|
user = User.objects.first()
|
|
|
|
processor = User.objects.last()
|
|
|
|
return cls(user, ticket, processor)
|