Skip to content

Commit

Permalink
fix: 修改NullBooleanField替换成BooleanField TencentBlueKing#1464
Browse files Browse the repository at this point in the history
  • Loading branch information
huangpixu committed Jan 7, 2025
1 parent 167cb00 commit 40366f6
Show file tree
Hide file tree
Showing 5 changed files with 371 additions and 204 deletions.
74 changes: 54 additions & 20 deletions itsm/component/auto_register/strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,34 @@
from distutils.version import StrictVersion

import django
from django.db.models import *
from django.db.models import * # noqa: F403
from django.conf import settings


def is_boolean(field):
return isinstance(field, (BooleanField, NullBooleanField))
return isinstance(field, (BooleanField))


def is_string(field):
return isinstance(field, (CharField, EmailField, IPAddressField, SlugField, URLField))
return isinstance(
field, (CharField, EmailField, IPAddressField, SlugField, URLField)
)


def is_number(field):
return isinstance(field, (IntegerField, SmallIntegerField, PositiveIntegerField,
PositiveSmallIntegerField, BigIntegerField,
CommaSeparatedIntegerField, DecimalField, FloatField))
return isinstance(
field,
(
IntegerField,
SmallIntegerField,
PositiveIntegerField,
PositiveSmallIntegerField,
BigIntegerField,
CommaSeparatedIntegerField,
DecimalField,
FloatField,
),
)


def is_datetime(field):
Expand All @@ -53,7 +65,7 @@ def is_file(field):


def is_binary(self, field):
if self.django_greater_than('1.6'):
if self.django_greater_than("1.6"):
return isinstance(field, (BinaryField))
else:
return False
Expand All @@ -69,6 +81,7 @@ class BaseStrategy:
"""
基础策略, 封装了策略所需要的字段判定方法
"""

type = None

def get_value(self, field_list: list) -> list:
Expand Down Expand Up @@ -101,24 +114,36 @@ class ListDisplayStrategy(BaseStrategy):
type = "list_display"

def is_matched(self, field: Field):
return is_string(field) or is_boolean(field) or \
is_number(field) or is_datetime(field)
return (
is_string(field)
or is_boolean(field)
or is_number(field)
or is_datetime(field)
)


class ListDisplayLinksStrategy(BaseStrategy):
type = "list_display_links"

def is_matched(self, field: Field):
return is_string(field) or is_boolean(field) \
or is_number(field) or is_datetime(field)
return (
is_string(field)
or is_boolean(field)
or is_number(field)
or is_datetime(field)
)


class ListFilterStrategy(BaseStrategy):
type = "list_filter"

def is_matched(self, field: Field):
return is_string(field) or is_boolean(field) \
or is_number(field) or is_datetime(field)
return (
is_string(field)
or is_boolean(field)
or is_number(field)
or is_datetime(field)
)


class SearchFieldsStrategy(BaseStrategy):
Expand All @@ -132,21 +157,29 @@ class ListPerPageStrategy(BaseStrategy):
type = "list_per_page"

def get_value(self, field_list):
return int(settings.DSA_LIST_PER_PAGE) if hasattr(settings, 'DSA_LIST_PER_PAGE') else 5
return (
int(settings.DSA_LIST_PER_PAGE)
if hasattr(settings, "DSA_LIST_PER_PAGE")
else 5
)


class ListMaxShowAllStrategy(BaseStrategy):
type = "list_max_show_all"

def get_value(self, field_list):
return int(settings.DSA_LIST_MAX_SHOW_ALL) if hasattr(settings,
'DSA_LIST_MAX_SHOW_ALL') else 50
return (
int(settings.DSA_LIST_MAX_SHOW_ALL)
if hasattr(settings, "DSA_LIST_MAX_SHOW_ALL")
else 50
)


class StrategyDispatcher(object):
"""
StrategyDispatcher 负责将不同的方法分派到不同的类中去处理
"""

STRATEGY_CLASS = [
ListRawIdFieldsStrategy,
ListDisplayStrategy,
Expand All @@ -155,15 +188,16 @@ class StrategyDispatcher(object):
SearchFieldsStrategy,
ListPerPageStrategy,
ListMaxShowAllStrategy,
FilterHorizontalStrategy
FilterHorizontalStrategy,
]

STRATEGY_DICT = dict(
[(_object.type, _object()) for _object in STRATEGY_CLASS])
STRATEGY_DICT = dict([(_object.type, _object()) for _object in STRATEGY_CLASS])

def __init__(self, strategy_type):
if strategy_type not in self.STRATEGY_DICT:
raise Exception("The strategy corresponding to Strategy_type does not exist")
raise Exception(
"The strategy corresponding to Strategy_type does not exist"
)

self.strategy_type = strategy_type

Expand Down
154 changes: 105 additions & 49 deletions itsm/ticket/migrations/0037_auto_20200212_1554.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,94 +34,150 @@
class Migration(migrations.Migration):

dependencies = [
('ticket', '0036_auto_20200114_1855'),
("ticket", "0036_auto_20200114_1855"),
]

operations = [
migrations.CreateModel(
name='SignTask',
name="SignTask",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('creator', models.CharField(blank=True, max_length=64, null=True, verbose_name='创建人')),
('create_at', models.DateTimeField(auto_now_add=True, verbose_name='创建时间')),
('update_at', models.DateTimeField(auto_now=True, verbose_name='更新时间')),
('updated_by', models.CharField(blank=True, max_length=64, null=True, verbose_name='修改人')),
('end_at', models.DateTimeField(blank=True, null=True, verbose_name='结束时间')),
('is_deleted', models.BooleanField(db_index=True, default=False, verbose_name='是否软删除')),
('status_id', models.IntegerField(verbose_name='状态ID')),
('order', models.IntegerField(default=-1, verbose_name='顺序')),
(
'status',
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"creator",
models.CharField(
blank=True, max_length=64, null=True, verbose_name="创建人"
),
),
(
"create_at",
models.DateTimeField(auto_now_add=True, verbose_name="创建时间"),
),
(
"update_at",
models.DateTimeField(auto_now=True, verbose_name="更新时间"),
),
(
"updated_by",
models.CharField(
blank=True, max_length=64, null=True, verbose_name="修改人"
),
),
(
"end_at",
models.DateTimeField(
blank=True, null=True, verbose_name="结束时间"
),
),
(
"is_deleted",
models.BooleanField(
db_index=True, default=False, verbose_name="是否软删除"
),
),
("status_id", models.IntegerField(verbose_name="状态ID")),
("order", models.IntegerField(default=-1, verbose_name="顺序")),
(
"status",
models.CharField(
choices=[('WAIT', '未激活'), ('RUNNING', '执行中'), ('FINISHED', '已完成')],
default='WAIT',
choices=[
("WAIT", "未激活"),
("RUNNING", "执行中"),
("FINISHED", "已完成"),
],
default="WAIT",
max_length=32,
verbose_name='任务状态',
verbose_name="任务状态",
),
),
('processor', models.CharField(max_length=255, verbose_name='处理人')),
('is_active', models.BooleanField(default=False, verbose_name='是否激活')),
('is_passed', models.NullBooleanField(verbose_name='是否审批通过')),
("processor", models.CharField(max_length=255, verbose_name="处理人")),
(
"is_active",
models.BooleanField(default=False, verbose_name="是否激活"),
),
(
"is_passed",
models.BooleanField(verbose_name="是否审批通过", null=True),
),
],
options={
"verbose_name": "会签任务",
"verbose_name_plural": "会签任务",
"ordering": ("-id",),
},
managers=[
("_objects", django.db.models.manager.Manager()),
],
options={'verbose_name': '会签任务', 'verbose_name_plural': '会签任务', 'ordering': ('-id',),},
managers=[('_objects', django.db.models.manager.Manager()),],
),
migrations.CreateModel(
name='TaskField',
name="TaskField",
fields=[
(
'ticketfield_ptr',
"ticketfield_ptr",
models.OneToOneField(
auto_created=True,
on_delete=django.db.models.deletion.CASCADE,
parent_link=True,
primary_key=True,
serialize=False,
to='ticket.TicketField',
to="ticket.TicketField",
),
),
],
options={'abstract': False,},
bases=('ticket.ticketfield',),
managers=[('_objects', django.db.models.manager.Manager()),],
options={
"abstract": False,
},
bases=("ticket.ticketfield",),
managers=[
("_objects", django.db.models.manager.Manager()),
],
),
migrations.AddField(
model_name='status', name='is_sequential', field=models.BooleanField(default=False, verbose_name='是否是串行任务'),
model_name="status",
name="is_sequential",
field=models.BooleanField(default=False, verbose_name="是否是串行任务"),
),
migrations.AddField(
model_name='status',
name='type',
model_name="status",
name="type",
field=models.CharField(
choices=[
('START', '开始节点(圆形)'),
('NORMAL', '普通节点'),
('SIGN', '会签节点'),
('TASK', '自动节点'),
('TASK-SOPS', '标准运维节点'),
('ROUTER', '分支网关节点(菱形)'),
('ROUTER-P', '并行网关节点'),
('COVERAGE', '汇聚网关节点'),
('END', '结束节点(圆形)'),
("START", "开始节点(圆形)"),
("NORMAL", "普通节点"),
("SIGN", "会签节点"),
("TASK", "自动节点"),
("TASK-SOPS", "标准运维节点"),
("ROUTER", "分支网关节点(菱形)"),
("ROUTER-P", "并行网关节点"),
("COVERAGE", "汇聚网关节点"),
("END", "结束节点(圆形)"),
],
default='NORMAL',
default="NORMAL",
max_length=32,
verbose_name='节点类型',
verbose_name="节点类型",
),
),
migrations.AlterField(
model_name='status',
name='action_type',
model_name="status",
name="action_type",
field=models.CharField(
choices=[
('TRANSITION', '提交'),
('DISTRIBUTE', '分派'),
('CLAIM', '认领'),
('SIGN', '会签'),
('AUTOMATIC', '自动执行'),
("TRANSITION", "提交"),
("DISTRIBUTE", "分派"),
("CLAIM", "认领"),
("SIGN", "会签"),
("AUTOMATIC", "自动执行"),
],
default='TRANSITION',
default="TRANSITION",
max_length=32,
verbose_name='节点内部操作类型',
verbose_name="节点内部操作类型",
),
),
]
Loading

0 comments on commit 40366f6

Please sign in to comment.