From beb43aa726f65fb2363de887ae2d959784ee665c Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Wed, 10 May 2023 15:19:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=B7=A5=E5=8D=95comment=E6=94=B9?= =?UTF-8?q?=E6=88=90md=E6=A0=BC=E5=BC=8F=20(#10419)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: feng <1304903146@qq.com> --- apps/tickets/handlers/base.py | 16 ++++++++-------- .../templates/tickets/ticket_approve_diff.html | 1 - 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/apps/tickets/handlers/base.py b/apps/tickets/handlers/base.py index 54713750e..674960692 100644 --- a/apps/tickets/handlers/base.py +++ b/apps/tickets/handlers/base.py @@ -1,14 +1,13 @@ -from html import escape - -from django.utils.translation import ugettext as _ +import html2text from django.template.loader import render_to_string +from django.utils.translation import ugettext as _ from common.utils import get_logger +from tickets.const import TicketState, TicketType from tickets.utils import ( send_ticket_processed_mail_to_applicant, send_ticket_applied_mail_to_assignees ) -from tickets.const import TicketState, TicketType logger = get_logger(__name__) @@ -98,7 +97,7 @@ class BaseHandler: approve_info = _('{} {} the ticket').format(user_display, state_display) context = self._diff_prev_approve_context(state) context.update({'approve_info': approve_info}) - body = self.reject_html_script( + body = self.safe_html_script( render_to_string('tickets/ticket_approve_diff.html', context) ) data = { @@ -111,6 +110,7 @@ class BaseHandler: return self.ticket.comments.create(**data) @staticmethod - def reject_html_script(unsafe_html): - safe_html = escape(unsafe_html) - return safe_html + def safe_html_script(unsafe_html): + unsafe_html = unsafe_html.replace('\n', '') + html_str = html2text.html2text(unsafe_html) + return html_str diff --git a/apps/tickets/templates/tickets/ticket_approve_diff.html b/apps/tickets/templates/tickets/ticket_approve_diff.html index 8426b34ed..79aad6b5c 100644 --- a/apps/tickets/templates/tickets/ticket_approve_diff.html +++ b/apps/tickets/templates/tickets/ticket_approve_diff.html @@ -18,7 +18,6 @@ {% endfor %} {% endfor %} - {% endif %}