Skip to content

Commit 30e44aa

Browse files
insistencegitee-org
authored andcommitted
!17 Dash-FastAPI-Admin v1.1.0
Merge pull request !17 from insistence/develop
2 parents cfc412b + 402ad06 commit 30e44aa

File tree

10 files changed

+92
-18
lines changed

10 files changed

+92
-18
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
<p align="center">
22
<img alt="logo" src="https://oscimg.oschina.net/oscnet/up-d3d0a9303e11d522a06cd263f3079027715.png">
33
</p>
4-
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.0.10</h1>
4+
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.1.0</h1>
55
<h4 align="center">基于Dash+FastAPI前后端分离的纯Python快速开发框架</h4>
66
<p align="center">
77
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/stargazers"><img src="https://gitee.com/insistence2022/dash-fastapi-admin/badge/star.svg?theme=dark"></a>
88
<a href="https://github.com/insistence/Dash-FastAPI-Admin"><img src="https://img.shields.io/github/stars/insistence/Dash-FastAPI-Admin?style=social"></a>
9-
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.0.10-brightgreen.svg"></a>
9+
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.1.0-brightgreen.svg"></a>
1010
<a href="https://gitee.com/insistence2022/dash-fastapi-admin/blob/master/LICENSE"><img src="https://img.shields.io/github/license/mashape/apistatus.svg"></a>
1111
<img src="https://img.shields.io/badge/python-3.8 | 3.9-blue">
1212
<img src="https://img.shields.io/badge/MySQL-≥5.7-blue">
1313
</p>
1414

15+
1516
## 平台简介
1617

1718
Dash-FastAPI-Admin是一套全部开源的快速开发平台,毫无保留给个人及企业免费使用。

dash-fastapi-backend/config/get_scheduler.py

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,49 @@ class MyCronTrigger(CronTrigger):
2020
@classmethod
2121
def from_crontab(cls, expr, timezone=None):
2222
values = expr.split()
23-
if len(values) != 7:
24-
raise ValueError('Wrong number of fields; got {}, expected 7'.format(len(values)))
23+
if len(values) != 6 and len(values) != 7:
24+
raise ValueError('Wrong number of fields; got {}, expected 6 or 7'.format(len(values)))
2525

26-
return cls(second=values[0], minute=values[1], hour=values[2], day=values[3], month=values[4],
27-
day_of_week=values[5], year=values[6], timezone=timezone)
26+
second = values[0]
27+
minute = values[1]
28+
hour = values[2]
29+
if '?' in values[3]:
30+
day = None
31+
elif 'L' in values[5]:
32+
day = f"last {values[5].replace('L', '')}"
33+
elif 'W' in values[3]:
34+
day = cls.__find_recent_workday(int(values[3].split('W')[0]))
35+
else:
36+
day = values[3].replace('L', 'last')
37+
month = values[4]
38+
if '?' in values[5] or 'L' in values[5]:
39+
week = None
40+
elif '#' in values[5]:
41+
week = int(values[5].split('#')[1])
42+
else:
43+
week = values[5]
44+
if '#' in values[5]:
45+
day_of_week = int(values[5].split('#')[0]) - 1
46+
else:
47+
day_of_week = None
48+
year = values[6] if len(values) == 7 else None
49+
return cls(second=second, minute=minute, hour=hour, day=day, month=month, week=week,
50+
day_of_week=day_of_week, year=year, timezone=timezone)
51+
52+
@classmethod
53+
def __find_recent_workday(cls, day):
54+
now = datetime.now()
55+
date = datetime(now.year, now.month, day)
56+
if date.weekday() < 5:
57+
return date.day
58+
else:
59+
diff = 1
60+
while True:
61+
previous_day = date - timedelta(days=diff)
62+
if previous_day.weekday() < 5:
63+
return previous_day.day
64+
else:
65+
diff += 1
2866

2967

3068
job_stores = {

dash-fastapi-backend/module_admin/dao/log_dao.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from sqlalchemy import asc, desc
12
from sqlalchemy.orm import Session
23
from module_admin.entity.do.log_do import SysOperLog, SysLogininfor
34
from module_admin.entity.vo.log_vo import OperLogModel, LogininforModel, OperLogQueryModel, LoginLogQueryModel
@@ -32,6 +33,12 @@ def get_operation_log_list(cls, db: Session, query_object: OperLogQueryModel):
3233
:param query_object: 查询参数对象
3334
:return: 操作日志列表信息对象
3435
"""
36+
if query_object.is_asc == 'ascend':
37+
order_by_column = asc(getattr(SysOperLog, query_object.order_by_column, None))
38+
elif query_object.is_asc == 'descend':
39+
order_by_column = desc(getattr(SysOperLog, query_object.order_by_column, None))
40+
else:
41+
order_by_column = asc(SysOperLog.oper_time)
3542
operation_log_list = db.query(SysOperLog) \
3643
.filter(SysOperLog.title.like(f'%{query_object.title}%') if query_object.title else True,
3744
SysOperLog.oper_name.like(f'%{query_object.oper_name}%') if query_object.oper_name else True,
@@ -42,7 +49,7 @@ def get_operation_log_list(cls, db: Session, query_object: OperLogQueryModel):
4249
datetime.combine(datetime.strptime(query_object.oper_time_end, '%Y-%m-%d'), time(23, 59, 59)))
4350
if query_object.oper_time_start and query_object.oper_time_end else True
4451
)\
45-
.distinct().all()
52+
.distinct().order_by(order_by_column).all()
4653

4754
return list_format_datetime(operation_log_list)
4855

@@ -96,6 +103,12 @@ def get_login_log_list(cls, db: Session, query_object: LoginLogQueryModel):
96103
:param query_object: 查询参数对象
97104
:return: 登录日志列表信息对象
98105
"""
106+
if query_object.is_asc == 'ascend':
107+
order_by_column = asc(getattr(SysLogininfor, query_object.order_by_column, None))
108+
elif query_object.is_asc == 'descend':
109+
order_by_column = desc(getattr(SysLogininfor, query_object.order_by_column, None))
110+
else:
111+
order_by_column = asc(SysLogininfor.login_time)
99112
login_log_list = db.query(SysLogininfor) \
100113
.filter(SysLogininfor.ipaddr.like(f'%{query_object.ipaddr}%') if query_object.ipaddr else True,
101114
SysLogininfor.user_name.like(f'%{query_object.user_name}%') if query_object.user_name else True,
@@ -105,7 +118,7 @@ def get_login_log_list(cls, db: Session, query_object: LoginLogQueryModel):
105118
datetime.combine(datetime.strptime(query_object.login_time_end, '%Y-%m-%d'), time(23, 59, 59)))
106119
if query_object.login_time_start and query_object.login_time_end else True
107120
)\
108-
.distinct().all()
121+
.distinct().order_by(order_by_column).all()
109122

110123
return list_format_datetime(login_log_list)
111124

dash-fastapi-backend/module_admin/entity/vo/log_vo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class OperLogQueryModel(OperLogModel):
5050
"""
5151
操作日志管理不分页查询模型
5252
"""
53+
order_by_column: Optional[str]
54+
is_asc: Optional[str]
5355
oper_time_start: Optional[str]
5456
oper_time_end: Optional[str]
5557

@@ -91,6 +93,8 @@ class LoginLogQueryModel(LogininforModel):
9193
"""
9294
登录日志管理不分页查询模型
9395
"""
96+
order_by_column: Optional[str]
97+
is_asc: Optional[str]
9498
login_time_start: Optional[str]
9599
login_time_end: Optional[str]
96100

dash-fastapi-backend/sql/dash-fastapi.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,9 @@ CREATE TABLE `sys_job` (
260260
-- ----------------------------
261261
-- Records of sys_job
262262
-- ----------------------------
263-
INSERT INTO `sys_job` VALUES (1, '系统默认(无参)', 'default', 'default', 'module_task.scheduler_test.job', 'test', NULL, '0/10 * * * * * *', '2', '0', '1', 'admin', '2023-05-23 16:13:34', 'admin', '2023-05-23 16:13:34', '');
264-
INSERT INTO `sys_job` VALUES (2, '系统默认(有参)', 'sqlalchemy', 'default', 'module_task.scheduler_test.job', 'new', '{\"test\": 111}', '0/15 * * * * * *', '1', '1', '1', 'admin', '2023-05-23 16:13:34', 'admin', '2023-05-23 16:13:34', '');
265-
INSERT INTO `sys_job` VALUES (3, '系统默认(多参)', 'redis', 'default', 'module_task.scheduler_test.job', NULL, NULL, '0/20 * * * * * *', '3', '1', '1', 'admin', '2023-05-23 16:13:34', '', NULL, '');
263+
INSERT INTO `sys_job` VALUES (1, '系统默认(无参)', 'default', 'default', 'module_task.scheduler_test.job', 'test', NULL, '0/10 * * * * ?', '2', '0', '1', 'admin', '2023-05-23 16:13:34', 'admin', '2023-05-23 16:13:34', '');
264+
INSERT INTO `sys_job` VALUES (2, '系统默认(有参)', 'sqlalchemy', 'default', 'module_task.scheduler_test.job', 'new', '{\"test\": 111}', '0/15 * * * * ?', '1', '1', '1', 'admin', '2023-05-23 16:13:34', 'admin', '2023-05-23 16:13:34', '');
265+
INSERT INTO `sys_job` VALUES (3, '系统默认(多参)', 'redis', 'default', 'module_task.scheduler_test.job', NULL, NULL, '0/20 * * * * ?', '3', '1', '1', 'admin', '2023-05-23 16:13:34', '', NULL, '');
266266

267267
-- ----------------------------
268268
-- Table structure for sys_job_log

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
inputs=dict(
2222
search_click=Input('login_log-search', 'nClicks'),
2323
refresh_click=Input('login_log-refresh', 'nClicks'),
24+
sorter=Input('login_log-list-table', 'sorter'),
2425
pagination=Input('login_log-list-table', 'pagination'),
2526
operations=Input('login_log-operations-store', 'data')
2627
),
@@ -33,7 +34,7 @@
3334
),
3435
prevent_initial_call=True
3536
)
36-
def get_login_log_table_data(search_click, refresh_click, pagination, operations, ipaddr, user_name, status_select, login_time_range, button_perms):
37+
def get_login_log_table_data(search_click, refresh_click, sorter, pagination, operations, ipaddr, user_name, status_select, login_time_range, button_perms):
3738
"""
3839
获取登录日志表格数据回调(进行表格相关增删查改操作后均会触发此回调)
3940
"""
@@ -49,17 +50,21 @@ def get_login_log_table_data(search_click, refresh_click, pagination, operations
4950
status=status_select,
5051
login_time_start=login_time_start,
5152
login_time_end=login_time_end,
53+
order_by_column=sorter.get('columns')[0] if sorter else None,
54+
is_asc=sorter.get('orders')[0] if sorter else None,
5255
page_num=1,
5356
page_size=10
5457
)
55-
triggered_id = dash.ctx.triggered_id
56-
if triggered_id == 'login_log-list-table':
58+
triggered_prop = dash.ctx.triggered[0].get('prop_id')
59+
if triggered_prop == 'login_log-list-table.pagination':
5760
query_params = dict(
5861
ipaddr=ipaddr,
5962
user_name=user_name,
6063
status=status_select,
6164
login_time_start=login_time_start,
6265
login_time_end=login_time_end,
66+
order_by_column=sorter.get('columns')[0] if sorter else None,
67+
is_asc=sorter.get('orders')[0] if sorter else None,
6368
page_num=pagination['current'],
6469
page_size=pagination['pageSize']
6570
)

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
inputs=dict(
2424
search_click=Input('operation_log-search', 'nClicks'),
2525
refresh_click=Input('operation_log-refresh', 'nClicks'),
26+
sorter=Input('operation_log-list-table', 'sorter'),
2627
pagination=Input('operation_log-list-table', 'pagination'),
2728
operations=Input('operation_log-operations-store', 'data')
2829
),
@@ -36,7 +37,7 @@
3637
),
3738
prevent_initial_call=True
3839
)
39-
def get_operation_log_table_data(search_click, refresh_click, pagination, operations, title, oper_name, business_type, status_select, oper_time_range, button_perms):
40+
def get_operation_log_table_data(search_click, refresh_click, sorter, pagination, operations, title, oper_name, business_type, status_select, oper_time_range, button_perms):
4041
"""
4142
获取操作日志表格数据回调(进行表格相关增删查改操作后均会触发此回调)
4243
"""
@@ -53,18 +54,22 @@ def get_operation_log_table_data(search_click, refresh_click, pagination, operat
5354
status=status_select,
5455
oper_time_start=oper_time_start,
5556
oper_time_end=oper_time_end,
57+
order_by_column=sorter.get('columns')[0] if sorter else None,
58+
is_asc=sorter.get('orders')[0] if sorter else None,
5659
page_num=1,
5760
page_size=10
5861
)
59-
triggered_id = dash.ctx.triggered_id
60-
if triggered_id == 'operation_log-list-table':
62+
triggered_prop = dash.ctx.triggered[0].get('prop_id')
63+
if triggered_prop == 'operation_log-list-table.pagination':
6164
query_params = dict(
6265
title=title,
6366
oper_name=oper_name,
6467
business_type=business_type,
6568
status=status_select,
6669
oper_time_start=oper_time_start,
6770
oper_time_end=oper_time_end,
71+
order_by_column=sorter.get('columns')[0] if sorter else None,
72+
is_asc=sorter.get('orders')[0] if sorter else None,
6873
page_num=pagination['current'],
6974
page_size=pagination['pageSize']
7075
)

dash-fastapi-frontend/views/monitor/logininfor/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,10 @@ def render(button_perms):
331331
rowSelectionType='checkbox',
332332
rowSelectionWidth=50,
333333
bordered=True,
334+
sortOptions={
335+
'sortDataIndexes': ['user_name', 'login_time'],
336+
'multiple': False
337+
},
334338
pagination={
335339
'pageSize': page_size,
336340
'current': page_num,

dash-fastapi-frontend/views/monitor/operlog/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,10 @@ def render(button_perms):
361361
rowSelectionType='checkbox',
362362
rowSelectionWidth=50,
363363
bordered=True,
364+
sortOptions={
365+
'sortDataIndexes': ['oper_name', 'oper_time'],
366+
'multiple': False
367+
},
364368
pagination={
365369
'pageSize': page_size,
366370
'current': page_num,

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ psutil==5.9.5
1717
PyMySQL==1.0.3
1818
python-jose[cryptography]==3.3.0
1919
redis==5.0.1
20-
requests==2.30.0
20+
requests==2.31.0
2121
SQLAlchemy==1.4.48
2222
user-agents==2.2.0
2323
waitress==2.1.2

0 commit comments

Comments
 (0)