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)