refactor(api):移除marshal序列化
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
from flask_restful import fields
|
||||
|
||||
from applications.extensions import db
|
||||
|
||||
from ..base import BaseModel
|
||||
@@ -12,15 +10,3 @@ class FilePhoto(db.Model, BaseModel):
|
||||
href = db.Column(db.String(255))
|
||||
mime = db.Column(db.CHAR(50), nullable=False)
|
||||
size = db.Column(db.CHAR(30), nullable=False)
|
||||
|
||||
@staticmethod
|
||||
def fields():
|
||||
return {
|
||||
'id': fields.Integer,
|
||||
'name': fields.String,
|
||||
'href': fields.String,
|
||||
'mime': fields.String,
|
||||
'size': fields.String,
|
||||
'ext': fields.String,
|
||||
'create_at': fields.DateTime,
|
||||
}
|
||||
|
||||
@@ -14,17 +14,3 @@ class LoggingModel(db.Model, BaseModel):
|
||||
ip = db.Column(db.String(255))
|
||||
success = db.Column(db.Boolean, default=True)
|
||||
user_agent = db.Column(db.Text)
|
||||
|
||||
@staticmethod
|
||||
def fields():
|
||||
return {
|
||||
'id': fields.Integer,
|
||||
'method': fields.String,
|
||||
'uid': fields.String,
|
||||
'url': fields.Url,
|
||||
'desc': fields.String,
|
||||
'ip': fields.String,
|
||||
'success': fields.Boolean,
|
||||
'user_agent': fields.String,
|
||||
'create_at': fields.DateTime,
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from flask_restful import fields
|
||||
|
||||
from applications.extensions import db
|
||||
from ..base import BaseModel
|
||||
|
||||
@@ -18,37 +16,3 @@ class RightsPower(db.Model, BaseModel):
|
||||
enable = db.Column(db.Boolean, comment='是否开启')
|
||||
|
||||
parent = db.relationship("RightsPower", remote_side=[id]) # 自关联
|
||||
|
||||
@staticmethod
|
||||
def fields():
|
||||
return {
|
||||
'powerId': fields.String(attribute="id"),
|
||||
'powerName': fields.String(attribute="name"),
|
||||
'powerType': fields.String(attribute="type"),
|
||||
'powerUrl': fields.String(attribute="url"),
|
||||
'openType': fields.String(attribute="open_type"),
|
||||
'parentId': fields.String(attribute="parent_id"),
|
||||
'icon': fields.String,
|
||||
'sort': fields.Integer,
|
||||
'create_at': fields.DateTime,
|
||||
'update_at': fields.DateTime,
|
||||
'enable': fields.Integer,
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def fields2():
|
||||
return {
|
||||
'id': fields.Integer,
|
||||
'title': fields.String(attribute="name"),
|
||||
'type': fields.String,
|
||||
'code': fields.String,
|
||||
'href': fields.String(attribute="url"),
|
||||
'openType': fields.String(attribute="open_type"),
|
||||
'parent_id': fields.Integer,
|
||||
'icon': fields.String,
|
||||
'sort': fields.Integer,
|
||||
'enable': fields.Boolean,
|
||||
'update_at': fields.DateTime,
|
||||
'create_at': fields.DateTime,
|
||||
|
||||
}
|
||||
|
||||
@@ -15,17 +15,3 @@ class RightsRole(db.Model, BaseModel):
|
||||
sort = db.Column(db.Integer, comment='排序')
|
||||
|
||||
power = db.relationship('RightsPower', secondary="rt_role_power", backref=db.backref('role'))
|
||||
|
||||
@staticmethod
|
||||
def fields():
|
||||
return {
|
||||
'id': fields.Integer,
|
||||
'roleName': fields.String(attribute="name"),
|
||||
'roleCode': fields.String(attribute="code"),
|
||||
'enable': fields.Boolean,
|
||||
'comment': fields.String,
|
||||
'details': fields.String,
|
||||
'sort': fields.Integer,
|
||||
'create_at': fields.DateTime,
|
||||
'update_at': fields.DateTime,
|
||||
}
|
||||
|
||||
@@ -18,6 +18,10 @@ class CompanyDepartment(db.Model, BaseModel):
|
||||
|
||||
@staticmethod
|
||||
def fields():
|
||||
"""
|
||||
定义模型的常用输出字段,新手请忽略。可以简化字段序列化操作,
|
||||
详细操作请查看 flask-restful marshal 的用法
|
||||
"""
|
||||
return {
|
||||
'deptId': fields.Integer(attribute="id"),
|
||||
'parentId': fields.Integer(attribute="parent_id"),
|
||||
|
||||
@@ -21,25 +21,9 @@ class CompanyUser(db.Model, UserMixin, BaseModel):
|
||||
role = db.relationship('RightsRole', secondary="rt_user_role", backref=db.backref('user'), lazy='dynamic')
|
||||
|
||||
def set_password(self, password):
|
||||
"""设置密码,对密码进行加密存储"""
|
||||
self.password_hash = generate_password_hash(password)
|
||||
|
||||
def validate_password(self, password):
|
||||
"""校验密码方法"""
|
||||
return check_password_hash(self.password_hash, password)
|
||||
|
||||
@staticmethod
|
||||
def fields():
|
||||
return {
|
||||
'id': fields.Integer,
|
||||
'username': fields.String,
|
||||
'realname': fields.String,
|
||||
'mobile': fields.String,
|
||||
'avatar': fields.Url,
|
||||
'comment': fields.String,
|
||||
# 'password_hash': fields.String,
|
||||
'enable': fields.Boolean,
|
||||
# 'dept_id': fields.Integer,
|
||||
'dept_id': fields.Integer,
|
||||
'create_at': fields.DateTime,
|
||||
'update_at': fields.DateTime,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user