From 6a9f1978bbf86b745eaeddc5657fb544f95db15e Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Mon, 16 Jan 2023 20:40:38 +0800 Subject: [PATCH] perf: ticket markdown (#9325) Co-authored-by: feng <1304903146@qq.com> --- apps/tickets/handlers/base.py | 7 +++---- apps/tickets/models/ticket/general.py | 5 ++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apps/tickets/handlers/base.py b/apps/tickets/handlers/base.py index e71d4297a..cfe2a526b 100644 --- a/apps/tickets/handlers/base.py +++ b/apps/tickets/handlers/base.py @@ -1,4 +1,4 @@ -from html import escape +import html2text from django.utils.translation import ugettext as _ from django.template.loader import render_to_string @@ -67,7 +67,7 @@ class BaseHandler: if state != TicketState.approved: return diff_context - if self.ticket.type == TicketType.apply_asset: + if self.ticket.type != TicketType.apply_asset: return diff_context # 企业微信,钉钉审批不做diff @@ -112,5 +112,4 @@ class BaseHandler: @staticmethod def safe_html_script(unsafe_html): - safe_html = escape(unsafe_html) - return safe_html + return html2text.html2text(unsafe_html) diff --git a/apps/tickets/models/ticket/general.py b/apps/tickets/models/ticket/general.py index 11a1db9dc..45fdbac32 100644 --- a/apps/tickets/models/ticket/general.py +++ b/apps/tickets/models/ticket/general.py @@ -399,7 +399,10 @@ class Ticket(StatusMixin, JMSBaseModel): elif isinstance(field, related.ForeignKey): value = self.rel_snapshot[name] elif isinstance(field, related.ManyToManyField): - value = ', '.join(self.rel_snapshot[name]) + if isinstance(self.rel_snapshot[name], str): + value = self.rel_snapshot[name] + elif isinstance(self.rel_snapshot[name], list): + value = ','.join(self.rel_snapshot[name]) elif isinstance(value, list): value = ', '.join(value) return value