refactor:修改pydantic数据校验模型名
This commit is contained in:
@@ -9,7 +9,7 @@ from extensions import db
|
||||
from models import DepartmentModel, UserModel
|
||||
|
||||
|
||||
class DeptModel(BaseModel):
|
||||
class DeptSchema(BaseModel):
|
||||
address: t.Optional[str]
|
||||
dept_name: t.Optional[str] = Field(alias='deptName')
|
||||
email: t.Optional[str]
|
||||
@@ -59,7 +59,7 @@ class DepartmentsApi(MethodView):
|
||||
, code=0)
|
||||
|
||||
@validate()
|
||||
def post(self, body: DeptModel):
|
||||
def post(self, body: DeptSchema):
|
||||
dept = DepartmentModel(
|
||||
parent_id=body.parent_id,
|
||||
dept_name=body.dept_name,
|
||||
@@ -76,7 +76,7 @@ class DepartmentsApi(MethodView):
|
||||
return success_api(message="成功")
|
||||
|
||||
@validate()
|
||||
def put(self, _id, body: DeptModel):
|
||||
def put(self, _id, body: DeptSchema):
|
||||
data = {
|
||||
"dept_name": body.dept_name,
|
||||
"sort": body.sort,
|
||||
@@ -88,9 +88,9 @@ class DepartmentsApi(MethodView):
|
||||
}
|
||||
body = DepartmentModel.query.filter_by(id=_id).update(data)
|
||||
if not body:
|
||||
return fail_api(message="更新失败")
|
||||
return {'success': False, 'message': "更新失败", 'code': 404}
|
||||
db.session.commit()
|
||||
return success_api(message="更新成功")
|
||||
return {'success': True, 'message': '更新成功', 'code': 200}
|
||||
|
||||
def delete(self, _id):
|
||||
ret = DepartmentModel.query.filter_by(id=_id).delete()
|
||||
|
||||
@@ -147,7 +147,7 @@ def make_menu_tree():
|
||||
return sorted(menu_dict.get(0), key=lambda item: item['sort'])
|
||||
|
||||
|
||||
class PowerModel(BaseModel):
|
||||
class PowerSchema(BaseModel):
|
||||
icon: str
|
||||
open_type: Optional[str] = Field(alias='openType')
|
||||
parent_id: Optional[str] = Field(alias='parentId')
|
||||
@@ -199,7 +199,7 @@ class RightsApi(MethodView):
|
||||
|
||||
class PowerApi(MethodView):
|
||||
@validate()
|
||||
def post(self, body: PowerModel):
|
||||
def post(self, body: PowerSchema):
|
||||
power = RightModel(
|
||||
icon=body.icon,
|
||||
open_type=body.open_type,
|
||||
@@ -239,7 +239,7 @@ class PowerApi(MethodView):
|
||||
return fail_api(message="删除失败")
|
||||
|
||||
@validate()
|
||||
def put(self, _id, body: PowerModel):
|
||||
def put(self, _id, body: PowerSchema):
|
||||
data = {
|
||||
"icon": body.icon,
|
||||
"open_type": body.open_type,
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from flask import Blueprint
|
||||
|
||||
from common import register_api
|
||||
from .file import FilePhotoAPI
|
||||
from .passport import LoginAPI
|
||||
|
||||
@@ -11,7 +11,7 @@ from common.utils.rights import record_logging
|
||||
from models import UserModel
|
||||
|
||||
|
||||
class LoginModel(BaseModel):
|
||||
class LoginSchema(BaseModel):
|
||||
username: str
|
||||
password: str
|
||||
captcha: str
|
||||
@@ -25,7 +25,7 @@ class LoginAPI(MethodView):
|
||||
return make_response(render_template('index/login.html'))
|
||||
|
||||
@validate()
|
||||
def post(self, body: LoginModel):
|
||||
def post(self, body: LoginSchema):
|
||||
s_code = session.get("code", None)
|
||||
session["code"] = None
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ def users_delete():
|
||||
return success_api(message="批量删除成功")
|
||||
|
||||
|
||||
class QueryModel(BaseModel):
|
||||
class QuerySchema(BaseModel):
|
||||
page: int = 1
|
||||
limit: int = 10
|
||||
real_name: t.Optional[str] = Field(alias='realName')
|
||||
@@ -78,7 +78,7 @@ class QueryModel(BaseModel):
|
||||
status: t.Optional[int]
|
||||
|
||||
|
||||
class PersonModel(BaseModel):
|
||||
class PersonSchema(BaseModel):
|
||||
role_ids: str = Field(alias='roleIds')
|
||||
username: str
|
||||
real_name: str = Field(alias='realName')
|
||||
@@ -89,7 +89,7 @@ class UserApi(MethodView):
|
||||
"""修改用户数据"""
|
||||
|
||||
@validate()
|
||||
def get(self, _id, query: QueryModel):
|
||||
def get(self, _id, query: QuerySchema):
|
||||
|
||||
filters = []
|
||||
|
||||
@@ -123,7 +123,7 @@ class UserApi(MethodView):
|
||||
)
|
||||
|
||||
@validate()
|
||||
def post(self, body: PersonModel):
|
||||
def post(self, body: PersonSchema):
|
||||
"""新建单个用户"""
|
||||
|
||||
role_ids = body.role_ids.split(',')
|
||||
|
||||
@@ -3,10 +3,6 @@ from flask import Blueprint, render_template
|
||||
document_bp = Blueprint('document', __name__)
|
||||
|
||||
|
||||
# @document_bp.route('view/document/button.html')
|
||||
# def document_button():
|
||||
# return render_template('view/document/button.html')
|
||||
|
||||
@document_bp.route('/component/code/index.html')
|
||||
def component_code():
|
||||
return render_template('component/code/index.html')
|
||||
|
||||
@@ -5,13 +5,6 @@ from models import RightModel
|
||||
from applications.view import index_bp
|
||||
|
||||
|
||||
# @index_bp.get('/rights/')
|
||||
# @view_logging_required
|
||||
# @permission_required("admin:power:main")
|
||||
# def rights_index():
|
||||
# return render_template('admin/rights/rights.html')
|
||||
|
||||
|
||||
@index_bp.get('/rights/power/<int:power_id>')
|
||||
@view_logging_required
|
||||
@permission_required("admin:power:edit")
|
||||
|
||||
@@ -20,25 +20,6 @@ class UserModel(db.Model, UserMixin):
|
||||
|
||||
role = db.relationship('RoleModel', secondary="rt_user_role", backref=db.backref('user'), lazy='dynamic')
|
||||
|
||||
"""
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='用户ID')
|
||||
username = db.Column(db.String(20), comment='用户名')
|
||||
password_hash = db.Column(db.String(128), comment='哈希密码')
|
||||
salt = db.Column(db.String(128))
|
||||
status = db.Column(db.String(20), default=0, comment='启用')
|
||||
realName = db.Column(db.String(20), comment='真实名字')
|
||||
email = db.Column(db.String(50), comment='邮箱')
|
||||
avatar = db.Column(db.String(255), comment='头像', default="/static/admin/admin/images/avatar.jpg")
|
||||
sex = db.Column(db.String(3), comment='性别')
|
||||
phone = db.Column(db.String(11), comment='电话号码')
|
||||
enable = db.Column(db.String(3), comment='启用')
|
||||
login = db.Column(db.String(3), comment='登录状态')
|
||||
# roleIds = db.Column(db.String(255), comment='登录状态')
|
||||
|
||||
comment = db.Column(db.String(255), comment='备注')
|
||||
dept_id = db.Column(db.Integer, comment='部门id')
|
||||
role = db.relationship('RoleModel', secondary="rt_user_role", backref=db.backref('user'), lazy='dynamic')
|
||||
"""
|
||||
def set_password(self, password):
|
||||
"""设置密码,对密码进行加密存储"""
|
||||
self.password_hash = generate_password_hash(password)
|
||||
@@ -65,14 +46,3 @@ class DepartmentModel(db.Model):
|
||||
sort = db.Column(db.Integer, comment="排序")
|
||||
|
||||
create_at = db.Column(db.DateTime, default=datetime.now, comment='创建时间')
|
||||
"""
|
||||
id = db.Column(db.Integer, primary_key=True, comment="部门ID")
|
||||
name = db.Column(db.String(50), comment="部门名称")
|
||||
userCount = db.Column(db.String(50), comment="部门人数")
|
||||
address = db.Column(db.String(255), comment="详细地址")
|
||||
leader = db.Column(db.String(50), comment="负责人")
|
||||
|
||||
status = db.Column(db.Boolean, comment='状态(1开启,0关闭)')
|
||||
parent_id = db.Column(db.Integer, comment="父级编号")
|
||||
sort = db.Column(db.Integer, comment="排序")
|
||||
"""
|
||||
Reference in New Issue
Block a user