From 167734ca5db8aaf7b56df4e9bcfc087dfe081033 Mon Sep 17 00:00:00 2001 From: fit2bot <68588906+fit2bot@users.noreply.github.com> Date: Thu, 31 Dec 2020 05:47:27 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E6=A8=A1=E5=9D=97=20(#5365)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: 优化工单模块 * feat: 优化工单模块2 Co-authored-by: Bai --- apps/tickets/models/ticket/mixin/base.py | 14 +++++++++++--- apps/tickets/signals_handler.py | 13 +++++++++---- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/apps/tickets/models/ticket/mixin/base.py b/apps/tickets/models/ticket/mixin/base.py index fdaeb50dc..c4ea304fb 100644 --- a/apps/tickets/models/ticket/mixin/base.py +++ b/apps/tickets/models/ticket/mixin/base.py @@ -106,6 +106,8 @@ class CreatePermissionMixin: class CreateCommentMixin: def create_comment(self, comment_body): + # 页面展示需要取消缩进 + comment_body = textwrap.dedent(comment_body) comment_data = { 'body': comment_body, 'user': self.processor, @@ -113,14 +115,20 @@ class CreateCommentMixin: } return self.comments.create(**comment_data) + def create_applied_comment(self): + comment_body = self.construct_applied_body() + self.create_comment(comment_body) + def create_approved_comment(self): comment_body = self.construct_approved_body() - # 页面展示需要取消缩进 - comment_body = textwrap.dedent(comment_body) self.create_comment(comment_body) def create_action_comment(self): + if self.has_applied: + user_display = self.applicant_display + if self.has_processed: + user_display = self.processor_display comment_body = __( - 'User {} {} the ticket'.format(self.processor_display, self.get_action_display()) + 'User {} {} the ticket'.format(user_display, self.get_action_display()) ) self.create_comment(comment_body) diff --git a/apps/tickets/signals_handler.py b/apps/tickets/signals_handler.py index bc5dd95e7..887cc1a79 100644 --- a/apps/tickets/signals_handler.py +++ b/apps/tickets/signals_handler.py @@ -23,14 +23,19 @@ def on_ticket_pre_save(sender, instance=None, **kwargs): @receiver(post_save, sender=Ticket) -def on_ticket_processed(sender, instance=None, **kwargs): - if not instance.has_processed: - return - logger.debug('Ticket is processed, send mail: {}'.format(instance.id)) +def on_ticket_post_save(sender, instance=None, **kwargs): instance.create_action_comment() + if instance.action_open: + instance.create_applied_comment() + return if instance.action_approve: instance.create_permission() instance.create_approved_comment() + logger.debug( + 'Ticket () has processed, send mail to applicant: {}'.format( + instance.title, instance.applicant_display + ) + ) send_ticket_processed_mail_to_applicant(instance)