Files
jumpserver/apps/tickets/models/ticket/mixin/base.py
Jiangjie.Bai 3b056ff953 reactor&feat: 重构工单模块 & 支持申请应用工单 (#5352)
* reactor: 修改工单Model,添加工单迁移文件

* reactor: 修改工单Model,添加工单迁移文件

* reactor: 重构工单模块

* reactor: 重构工单模块2

* reactor: 重构工单模块3

* reactor: 重构工单模块4

* reactor: 重构工单模块5

* reactor: 重构工单模块6

* reactor: 重构工单模块7

* reactor: 重构工单模块8

* reactor: 重构工单模块9

* reactor: 重构工单模块10

* reactor: 重构工单模块11

* reactor: 重构工单模块12

* reactor: 重构工单模块13

* reactor: 重构工单模块14

* reactor: 重构工单模块15

* reactor: 重构工单模块16

* reactor: 重构工单模块17

* reactor: 重构工单模块18

* reactor: 重构工单模块19

* reactor: 重构工单模块20

* reactor: 重构工单模块21

* reactor: 重构工单模块22

* reactor: 重构工单模块23

* reactor: 重构工单模块24

* reactor: 重构工单模块25

* reactor: 重构工单模块26

* reactor: 重构工单模块27

* reactor: 重构工单模块28

* reactor: 重构工单模块29

* reactor: 重构工单模块30

* reactor: 重构工单模块31

* reactor: 重构工单模块32

* reactor: 重构工单模块33

* reactor: 重构工单模块34

* reactor: 重构工单模块35

* reactor: 重构工单模块36

* reactor: 重构工单模块37

* reactor: 重构工单模块38

* reactor: 重构工单模块39
2020-12-30 00:19:59 +08:00

101 lines
3.0 KiB
Python

import textwrap
from django.utils.translation import ugettext as __
class ConstructBodyMixin:
# applied body
def construct_applied_body(self):
construct_method = getattr(self, f'construct_{self.type}_applied_body', lambda: 'No')
applied_body = construct_method()
body = '''
{}:
{}
'''.format(
__('Ticket applied info'),
applied_body
)
return body
# approved body
def construct_approved_body(self):
construct_method = getattr(self, f'construct_{self.type}_approved_body', lambda: 'No')
approved_body = construct_method()
body = '''
{}:
{}
'''.format(
__('Ticket approved info'),
approved_body
)
return body
# meta body
def construct_meta_body(self):
applied_body = self.construct_applied_body()
if not self.is_approved:
return applied_body
approved_body = self.construct_approved_body()
return applied_body + approved_body
# basic body
def construct_basic_body(self):
basic_body = '''
{}:
{}: {},
{}: {},
{}: {},
{}: {},
{}: {},
{}: {},
{}: {}
'''.format(
__("Ticket basic info"),
__('Ticket title'), self.title,
__('Ticket type'), self.get_type_display(),
__('Ticket applicant'), self.applicant_display,
__('Ticket assignees'), self.assignees_display,
__('Ticket processor'), self.processor_display,
__('Ticket action'), self.get_action_display(),
__('Ticket status'), self.get_status_display()
)
return basic_body
@property
def body(self):
old_body = self.meta.get('body')
if old_body:
# 之前版本的body
return old_body
basic_body = self.construct_basic_body()
meta_body = self.construct_meta_body()
return basic_body + meta_body
class CreatePermissionMixin:
# create permission
def create_permission(self):
create_method = getattr(self, f'create_{self.type}_permission', lambda: None)
create_method()
class CreateCommentMixin:
def create_comment(self, comment_body):
comment_data = {
'body': comment_body,
'user': self.processor,
'user_display': self.processor_display
}
return self.comments.create(**comment_data)
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):
comment_body = __(
'User {} {} the ticket'.format(self.processor_display, self.get_action_display())
)
self.create_comment(comment_body)