Skip to content

Commit e574d1b

Browse files
insistencegitee-org
authored andcommitted
!23 Dash-FastAPI-Admin 1.4.1
Merge pull request !23 from insistence/develop
2 parents d6bf0e3 + d504a80 commit e574d1b

File tree

7 files changed

+58
-23
lines changed

7 files changed

+58
-23
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
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.4.0</h1>
4+
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">Dash-FastAPI-Admin v1.4.1</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.4.0-brightgreen.svg"></a>
9+
<a href="https://gitee.com/insistence2022/dash-fastapi-admin"><img src="https://img.shields.io/badge/DashFastAPIAdmin-v1.4.1-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">
@@ -17,6 +17,7 @@
1717

1818

1919

20+
2021
## 平台简介
2122

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

dash-fastapi-backend/.env.dev

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.4.0'
13+
APP_VERSION= '1.4.1'
1414
# 应用是否开启热重载
1515
APP_RELOAD = true
1616
# 应用是否开启IP归属区域查询
@@ -42,6 +42,14 @@ DB_PASSWORD = 'mysqlroot'
4242
DB_DATABASE = 'dash-fastapi'
4343
# 是否开启sqlalchemy日志
4444
DB_ECHO = true
45+
# 允许溢出连接池大小的最大连接数
46+
DB_MAX_OVERFLOW = 10
47+
# 连接池大小,0表示连接数无限制
48+
DB_POOL_SIZE = 50
49+
# 连接回收时间(单位:秒)
50+
DB_POOL_RECYCLE = 3600
51+
# 连接池中没有线程可用时,最多等待的时间(单位:秒)
52+
DB_POOL_TIMEOUT = 30
4553

4654
# -------- Redis配置 --------
4755
# Redis主机

dash-fastapi-backend/.env.prod

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ APP_HOST = '0.0.0.0'
1010
# 应用端口
1111
APP_PORT = 9099
1212
# 应用版本
13-
APP_VERSION= '1.4.0'
13+
APP_VERSION= '1.4.1'
1414
# 应用是否开启热重载
1515
APP_RELOAD = false
1616
# 应用是否开启IP归属区域查询
@@ -42,6 +42,14 @@ DB_PASSWORD = 'mysqlroot'
4242
DB_DATABASE = 'dash-fastapi'
4343
# 是否开启sqlalchemy日志
4444
DB_ECHO = true
45+
# 允许溢出连接池大小的最大连接数
46+
DB_MAX_OVERFLOW = 10
47+
# 连接池大小,0表示连接数无限制
48+
DB_POOL_SIZE = 50
49+
# 连接回收时间(单位:秒)
50+
DB_POOL_RECYCLE = 3600
51+
# 连接池中没有线程可用时,最多等待的时间(单位:秒)
52+
DB_POOL_TIMEOUT = 30
4553

4654
# -------- Redis配置 --------
4755
# Redis主机

dash-fastapi-backend/config/database.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
f"{DataBaseConfig.db_host}:{DataBaseConfig.db_port}/{DataBaseConfig.db_database}"
99

1010
engine = create_engine(
11-
SQLALCHEMY_DATABASE_URL, echo=DataBaseConfig.db_echo
11+
SQLALCHEMY_DATABASE_URL,
12+
echo=DataBaseConfig.db_echo,
13+
max_overflow=DataBaseConfig.db_max_overflow,
14+
pool_size=DataBaseConfig.db_pool_size,
15+
pool_recycle=DataBaseConfig.db_pool_recycle,
16+
pool_timeout=DataBaseConfig.db_pool_timeout
1217
)
1318
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
1419
Base = declarative_base()

dash-fastapi-backend/config/env.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ class DataBaseSettings(BaseSettings):
4141
db_password: str = 'mysqlroot'
4242
db_database: str = 'dash-fastapi'
4343
db_echo: bool = True
44+
db_max_overflow: int = 10
45+
db_pool_size: int = 50
46+
db_pool_recycle: int = 3600
47+
db_pool_timeout: int = 30
4448

4549

4650
class RedisSettings(BaseSettings):

dash-fastapi-backend/module_admin/annotation/log_annotation.py

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from functools import wraps
1+
from functools import wraps, lru_cache
22
from fastapi import Request
33
from fastapi.responses import JSONResponse, ORJSONResponse, UJSONResponse
44
import inspect
@@ -52,21 +52,7 @@ async def wrapper(*args, **kwargs):
5252
oper_ip = request.headers.get('remote_addr') if request.headers.get('is_browser') == 'no' else request.headers.get('X-Forwarded-For')
5353
oper_location = '内网IP'
5454
if AppConfig.app_ip_location_query:
55-
try:
56-
if oper_ip != '127.0.0.1' and oper_ip != 'localhost':
57-
ip_result = requests.get(f'https://qifu-api.baidubce.com/ip/geo/v1/district?ip={oper_ip}')
58-
if ip_result.status_code == 200:
59-
prov = ip_result.json().get('data').get('prov')
60-
city = ip_result.json().get('data').get('city')
61-
if prov or city:
62-
oper_location = f'{prov}-{city}'
63-
else:
64-
oper_location = '未知'
65-
else:
66-
oper_location = '未知'
67-
except Exception as e:
68-
oper_location = '未知'
69-
print(e)
55+
oper_location = get_ip_location(oper_ip)
7056
# 根据不同的请求类型使用不同的方法获取请求参数
7157
content_type = request.headers.get("Content-Type")
7258
if content_type and ("multipart/form-data" in content_type or 'application/x-www-form-urlencoded' in content_type):
@@ -167,3 +153,26 @@ async def wrapper(*args, **kwargs):
167153
return wrapper
168154

169155
return decorator
156+
157+
158+
@lru_cache()
159+
def get_ip_location(oper_ip: str):
160+
"""
161+
查询ip归属区域
162+
:param oper_ip: 需要查询的ip
163+
:return: ip归属区域
164+
"""
165+
oper_location = '内网IP'
166+
try:
167+
if oper_ip != '127.0.0.1' and oper_ip != 'localhost':
168+
oper_location = '未知'
169+
ip_result = requests.get(f'https://qifu-api.baidubce.com/ip/geo/v1/district?ip={oper_ip}')
170+
if ip_result.status_code == 200:
171+
prov = ip_result.json().get('data').get('prov')
172+
city = ip_result.json().get('data').get('city')
173+
if prov or city:
174+
oper_location = f'{prov}-{city}'
175+
except Exception as e:
176+
oper_location = '未知'
177+
print(e)
178+
return oper_location

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ def get_role_detail_by_id(cls, db: Session, role_id: int):
7373
query_role_menu_info = db.query(SysMenu).select_from(SysRole) \
7474
.filter(SysRole.del_flag == 0, SysRole.role_id == role_id) \
7575
.outerjoin(SysRoleMenu, SysRole.role_id == SysRoleMenu.role_id) \
76-
.outerjoin(SysMenu, and_(SysRoleMenu.menu_id == SysMenu.menu_id, SysMenu.status == 0)) \
76+
.join(SysMenu, and_(SysRoleMenu.menu_id == SysMenu.menu_id, SysMenu.status == 0)) \
7777
.distinct().all()
7878
query_role_dept_info = db.query(SysDept).select_from(SysRole) \
7979
.filter(SysRole.del_flag == 0, SysRole.role_id == role_id) \
8080
.outerjoin(SysRoleDept, SysRole.role_id == SysRoleDept.role_id) \
81-
.outerjoin(SysDept, and_(SysRoleDept.dept_id == SysDept.dept_id, SysDept.status == 0, SysDept.del_flag == 0)) \
81+
.join(SysDept, and_(SysRoleDept.dept_id == SysDept.dept_id, SysDept.status == 0, SysDept.del_flag == 0)) \
8282
.distinct().all()
8383
results = dict(
8484
role=object_format_datetime(query_role_basic_info),

0 commit comments

Comments
 (0)