Skip to content

Commit ebafada

Browse files
committed
refactor: 重构utils/tree_tool.py和utils/common.py
1 parent d593afe commit ebafada

File tree

21 files changed

+482
-445
lines changed

21 files changed

+482
-445
lines changed

dash-fastapi-frontend/callbacks/forget_c.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dash.exceptions import PreventUpdate
44
from api.forget import ForgetApi
55
from server import app
6-
from utils.common import validate_data_not_empty
6+
from utils.common_util import ValidateUtil
77
from utils.feedback_util import MessageManager
88

99

@@ -51,7 +51,7 @@ def forget_auth(
5151
if nClicks:
5252
# 校验全部输入值是否不为空
5353
if all(
54-
validate_data_not_empty(item)
54+
ValidateUtil.not_empty(item)
5555
for item in [username, password, password_again, input_captcha]
5656
):
5757
if password == password_again:
@@ -92,28 +92,28 @@ def forget_auth(
9292

9393
return dict(
9494
username_form_status=None
95-
if validate_data_not_empty(username)
95+
if ValidateUtil.not_empty(username)
9696
else 'error',
9797
password_form_status=None
98-
if validate_data_not_empty(password)
98+
if ValidateUtil.not_empty(password)
9999
else 'error',
100100
password_again_form_status=None
101-
if validate_data_not_empty(password_again)
101+
if ValidateUtil.not_empty(password_again)
102102
else 'error',
103103
captcha_form_status=None
104-
if validate_data_not_empty(input_captcha)
104+
if ValidateUtil.not_empty(input_captcha)
105105
else 'error',
106106
username_form_help=None
107-
if validate_data_not_empty(username)
107+
if ValidateUtil.not_empty(username)
108108
else '请输入用户名!',
109109
password_form_help=None
110-
if validate_data_not_empty(password)
110+
if ValidateUtil.not_empty(password)
111111
else '请输入新密码!',
112112
password_again_form_help=None
113-
if validate_data_not_empty(password_again)
113+
if ValidateUtil.not_empty(password_again)
114114
else '请再次输入新密码!',
115115
captcha_form_help=None
116-
if validate_data_not_empty(input_captcha)
116+
if ValidateUtil.not_empty(input_captcha)
117117
else '请输入短信验证码!',
118118
redirect_container=None,
119119
)

dash-fastapi-frontend/callbacks/login_c.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from flask import session
77
from api.login import LoginApi
88
from server import app
9-
from utils.common import validate_data_not_empty
9+
from utils.common_util import ValidateUtil
1010
from utils.feedback_util import MessageManager
1111

1212

@@ -60,7 +60,7 @@ def login_auth(
6060
if captcha_hidden:
6161
validate_list = [username, password]
6262
# 校验全部输入值是否不为空
63-
if all(validate_data_not_empty(item) for item in validate_list):
63+
if all(ValidateUtil.not_empty(item) for item in validate_list):
6464
user_params = dict(
6565
username=username,
6666
password=password,
@@ -87,22 +87,22 @@ def login_auth(
8787

8888
return dict(
8989
username_form_status=None
90-
if validate_data_not_empty(username)
90+
if ValidateUtil.not_empty(username)
9191
else 'error',
9292
password_form_status=None
93-
if validate_data_not_empty(password)
93+
if ValidateUtil.not_empty(password)
9494
else 'error',
9595
captcha_form_status=None
96-
if validate_data_not_empty(input_captcha)
96+
if ValidateUtil.not_empty(input_captcha)
9797
else 'error',
9898
username_form_help=None
99-
if validate_data_not_empty(username)
99+
if ValidateUtil.not_empty(username)
100100
else '请输入用户名!',
101101
password_form_help=None
102-
if validate_data_not_empty(password)
102+
if ValidateUtil.not_empty(password)
103103
else '请输入密码!',
104104
captcha_form_help=None
105-
if validate_data_not_empty(input_captcha)
105+
if ValidateUtil.not_empty(input_captcha)
106106
else '请输入验证码!',
107107
token=None,
108108
redirect_container=None,

dash-fastapi-frontend/callbacks/monitor_c/job_c/job_c.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from api.monitor.job import JobApi
88
from config.constant import SysJobStatusConstant
99
from server import app
10-
from utils.common import validate_data_not_empty
10+
from utils.common_util import ValidateUtil
1111
from utils.dict_util import DictManager
1212
from utils.feedback_util import MessageManager
1313
from utils.permission_util import PermissionManager
@@ -361,7 +361,7 @@ def job_confirm(confirm_trigger, modal_type, form_value, form_label):
361361
x['id']['index']: x.get('value') for x in ctx.states_list[-1]
362362
}
363363
if all(
364-
validate_data_not_empty(item)
364+
ValidateUtil.not_empty(item)
365365
for item in [form_value.get(k) for k in form_label_list]
366366
):
367367
params_add = form_value
@@ -400,13 +400,13 @@ def job_confirm(confirm_trigger, modal_type, form_value, form_label):
400400
return dict(
401401
form_label_validate_status={
402402
form_label_state.get(k): None
403-
if validate_data_not_empty(form_value.get(k))
403+
if ValidateUtil.not_empty(form_value.get(k))
404404
else 'error'
405405
for k in form_label_list
406406
},
407407
form_label_validate_info={
408408
form_label_state.get(k): None
409-
if validate_data_not_empty(form_value.get(k))
409+
if ValidateUtil.not_empty(form_value.get(k))
410410
else f'{form_label_state.get(k)}不能为空!'
411411
for k in form_label_list
412412
},

dash-fastapi-frontend/callbacks/register_c.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from api.login import LoginApi
66
from api.register import RegisterApi
77
from server import app
8-
from utils.common import validate_data_not_empty
8+
from utils.common_util import ValidateUtil
99
from utils.feedback_util import MessageManager
1010

1111

@@ -70,7 +70,7 @@ def register(
7070
if captcha_hidden:
7171
validate_list = [username, password, confirm_password]
7272
# 校验全部输入值是否不为空
73-
if all(validate_data_not_empty(item) for item in validate_list):
73+
if all(ValidateUtil.not_empty(item) for item in validate_list):
7474
if password == confirm_password:
7575
register_params = dict(
7676
username=username,
@@ -112,28 +112,28 @@ def register(
112112

113113
return dict(
114114
username_form_status=None
115-
if validate_data_not_empty(username)
115+
if ValidateUtil.not_empty(username)
116116
else 'error',
117117
password_form_status=None
118-
if validate_data_not_empty(password)
118+
if ValidateUtil.not_empty(password)
119119
else 'error',
120120
confirm_password_form_status=None
121-
if validate_data_not_empty(confirm_password)
121+
if ValidateUtil.not_empty(confirm_password)
122122
else 'error',
123123
captcha_form_status=None
124-
if validate_data_not_empty(input_captcha)
124+
if ValidateUtil.not_empty(input_captcha)
125125
else 'error',
126126
username_form_help=None
127-
if validate_data_not_empty(username)
127+
if ValidateUtil.not_empty(username)
128128
else '请输入用户名!',
129129
password_form_help=None
130-
if validate_data_not_empty(password)
130+
if ValidateUtil.not_empty(password)
131131
else '请输入密码!',
132132
confirm_password_form_help=None
133-
if validate_data_not_empty(confirm_password)
133+
if ValidateUtil.not_empty(confirm_password)
134134
else '请再次输入密码!',
135135
captcha_form_help=None
136-
if validate_data_not_empty(input_captcha)
136+
if ValidateUtil.not_empty(input_captcha)
137137
else '请输入验证码!',
138138
redirect_container=None,
139139
register_success=None,

dash-fastapi-frontend/callbacks/system_c/config_c.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from api.system.config import ConfigApi
88
from config.constant import SysYesNoConstant
99
from server import app
10-
from utils.common import validate_data_not_empty
10+
from utils.common_util import ValidateUtil
1111
from utils.dict_util import DictManager
1212
from utils.feedback_util import MessageManager
1313
from utils.permission_util import PermissionManager
@@ -361,7 +361,7 @@ def config_confirm(confirm_trigger, modal_type, form_value, form_label):
361361
x['id']['index']: x.get('value') for x in ctx.states_list[-1]
362362
}
363363
if all(
364-
validate_data_not_empty(item)
364+
ValidateUtil.not_empty(item)
365365
for item in [form_value.get(k) for k in form_label_list]
366366
):
367367
params_add = form_value
@@ -400,13 +400,13 @@ def config_confirm(confirm_trigger, modal_type, form_value, form_label):
400400
return dict(
401401
form_label_validate_status={
402402
form_label_state.get(k): None
403-
if validate_data_not_empty(form_value.get(k))
403+
if ValidateUtil.not_empty(form_value.get(k))
404404
else 'error'
405405
for k in form_label_list
406406
},
407407
form_label_validate_info={
408408
form_label_state.get(k): None
409-
if validate_data_not_empty(form_value.get(k))
409+
if ValidateUtil.not_empty(form_value.get(k))
410410
else f'{form_label_state.get(k)}不能为空!'
411411
for k in form_label_list
412412
},

dash-fastapi-frontend/callbacks/system_c/dept_c.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
from api.system.dept import DeptApi
77
from config.constant import SysNormalDisableConstant
88
from server import app
9-
from utils.common import validate_data_not_empty
9+
from utils.common_util import ValidateUtil
1010
from utils.dict_util import DictManager
1111
from utils.feedback_util import MessageManager
1212
from utils.permission_util import PermissionManager
1313
from utils.time_format_util import TimeFormatUtil
14-
from utils.tree_tool import list_to_tree, list_to_tree_select
14+
from utils.tree_util import TreeUtil
1515

1616

1717
def generate_dept_table(query_params: Dict):
@@ -71,7 +71,7 @@ def generate_dept_table(query_params: Dict):
7171
item['status'] = DictManager.get_dict_tag(
7272
dict_type='sys_normal_disable', dict_value=item.get('status')
7373
)
74-
table_data_new = list_to_tree(table_data, 'dept_id', 'parent_id')
74+
table_data_new = TreeUtil.list_to_tree(table_data, 'dept_id', 'parent_id')
7575

7676
return [table_data_new, default_expanded_row_keys]
7777

@@ -256,12 +256,8 @@ def add_edit_dept_modal(
256256
else:
257257
dept_params = dict(dept_name='')
258258
tree_info = DeptApi.list_dept(dept_params)
259-
tree_data = list_to_tree_select(
260-
tree_info['data'],
261-
'dept_name',
262-
'dept_id',
263-
'dept_id',
264-
'parent_id',
259+
tree_data = TreeUtil.list_to_tree_select(
260+
tree_info['data'], 'dept_name', 'dept_id', 'dept_id', 'parent_id'
265261
)
266262

267263
if trigger_id == {
@@ -344,7 +340,7 @@ def dept_confirm(confirm_trigger, modal_type, form_value, form_label):
344340
x['id']['index']: x.get('value') for x in ctx.states_list[-1]
345341
}
346342
if all(
347-
validate_data_not_empty(item)
343+
ValidateUtil.not_empty(item)
348344
for item in [form_value.get(k) for k in form_label_list]
349345
):
350346
params_add = form_value
@@ -383,13 +379,13 @@ def dept_confirm(confirm_trigger, modal_type, form_value, form_label):
383379
return dict(
384380
form_label_validate_status={
385381
form_label_state.get(k): None
386-
if validate_data_not_empty(form_value.get(k))
382+
if ValidateUtil.not_empty(form_value.get(k))
387383
else 'error'
388384
for k in form_label_list
389385
},
390386
form_label_validate_info={
391387
form_label_state.get(k): None
392-
if validate_data_not_empty(form_value.get(k))
388+
if ValidateUtil.not_empty(form_value.get(k))
393389
else f'{form_label_state.get(k)}不能为空!'
394390
for k in form_label_list
395391
},

dash-fastapi-frontend/callbacks/system_c/dict_c/dict_c.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from config.constant import SysNormalDisableConstant
99
from server import app
1010
from utils.cache_util import TTLCacheManager
11-
from utils.common import validate_data_not_empty
11+
from utils.common_util import ValidateUtil
1212
from utils.dict_util import DictManager
1313
from utils.feedback_util import MessageManager
1414
from utils.permission_util import PermissionManager
@@ -370,7 +370,7 @@ def dict_type_confirm(confirm_trigger, modal_type, form_value, form_label):
370370
x['id']['index']: x.get('value') for x in ctx.states_list[-1]
371371
}
372372
if all(
373-
validate_data_not_empty(item)
373+
ValidateUtil.not_empty(item)
374374
for item in [form_value.get(k) for k in form_label_list]
375375
):
376376
params_add = form_value
@@ -410,13 +410,13 @@ def dict_type_confirm(confirm_trigger, modal_type, form_value, form_label):
410410
return dict(
411411
form_label_validate_status={
412412
form_label_state.get(k): None
413-
if validate_data_not_empty(form_value.get(k))
413+
if ValidateUtil.not_empty(form_value.get(k))
414414
else 'error'
415415
for k in form_label_list
416416
},
417417
form_label_validate_info={
418418
form_label_state.get(k): None
419-
if validate_data_not_empty(form_value.get(k))
419+
if ValidateUtil.not_empty(form_value.get(k))
420420
else f'{form_label_state.get(k)}不能为空!'
421421
for k in form_label_list
422422
},

dash-fastapi-frontend/callbacks/system_c/dict_c/dict_data_c.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from config.constant import SysNormalDisableConstant
88
from server import app
99
from utils.cache_util import TTLCacheManager
10-
from utils.common import validate_data_not_empty
10+
from utils.common_util import ValidateUtil
1111
from utils.dict_util import DictManager
1212
from utils.feedback_util import MessageManager
1313
from utils.permission_util import PermissionManager
@@ -349,7 +349,7 @@ def dict_data_confirm(confirm_trigger, modal_type, form_value, form_label):
349349
x['id']['index']: x.get('value') for x in ctx.states_list[-1]
350350
}
351351
if all(
352-
validate_data_not_empty(item)
352+
ValidateUtil.not_empty(item)
353353
for item in [form_value.get(k) for k in form_label_list]
354354
):
355355
params_add = form_value
@@ -390,13 +390,13 @@ def dict_data_confirm(confirm_trigger, modal_type, form_value, form_label):
390390
return dict(
391391
form_label_validate_status={
392392
form_label_state.get(k): None
393-
if validate_data_not_empty(form_value.get(k))
393+
if ValidateUtil.not_empty(form_value.get(k))
394394
else 'error'
395395
for k in form_label_list
396396
},
397397
form_label_validate_info={
398398
form_label_state.get(k): None
399-
if validate_data_not_empty(form_value.get(k))
399+
if ValidateUtil.not_empty(form_value.get(k))
400400
else f'{form_label_state.get(k)}不能为空!'
401401
for k in form_label_list
402402
},

dash-fastapi-frontend/callbacks/system_c/menu_c/components_c/button_type_c.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from dash.exceptions import PreventUpdate
44
from api.system.menu import MenuApi
55
from server import app
6-
from utils.common import validate_data_not_empty
6+
from utils.common_util import ValidateUtil
77
from utils.feedback_util import MessageManager
88

99

@@ -66,7 +66,7 @@ def menu_confirm_button(
6666
"""
6767
if confirm_trigger:
6868
if all(
69-
validate_data_not_empty(item)
69+
ValidateUtil.not_empty(item)
7070
for item in [parent_id, menu_name, order_num]
7171
):
7272
params_add = dict(
@@ -116,17 +116,17 @@ def menu_confirm_button(
116116

117117
return dict(
118118
form_validate=[
119-
None if validate_data_not_empty(parent_id) else 'error',
120-
None if validate_data_not_empty(menu_name) else 'error',
121-
None if validate_data_not_empty(order_num) else 'error',
119+
None if ValidateUtil.not_empty(parent_id) else 'error',
120+
None if ValidateUtil.not_empty(menu_name) else 'error',
121+
None if ValidateUtil.not_empty(order_num) else 'error',
122122
None
123-
if validate_data_not_empty(parent_id)
123+
if ValidateUtil.not_empty(parent_id)
124124
else '请选择上级菜单!',
125125
None
126-
if validate_data_not_empty(menu_name)
126+
if ValidateUtil.not_empty(menu_name)
127127
else '请输入菜单名称!',
128128
None
129-
if validate_data_not_empty(order_num)
129+
if ValidateUtil.not_empty(order_num)
130130
else '请输入显示排序!',
131131
],
132132
modal_visible=no_update,

0 commit comments

Comments
 (0)