''wip(semantic):调整序列化返回结果

This commit is contained in:
zhengxinonly
2021-09-15 00:45:35 +08:00
parent 550f99e468
commit 316ebc2441
21 changed files with 200 additions and 164 deletions
+14
View File
@@ -1,3 +1,5 @@
from flask_restful import fields
from applications.extensions import db
from ..base import BaseModel
@@ -10,3 +12,15 @@ 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,
}
+16
View File
@@ -1,3 +1,5 @@
from flask_restful import fields
from applications.extensions import db
from .base import BaseModel
@@ -12,3 +14,17 @@ 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,
}
+36 -5
View File
@@ -1,4 +1,4 @@
import datetime
from flask_restful import fields
from applications.extensions import db
from ..base import BaseModel
@@ -15,9 +15,40 @@ class RightsPower(db.Model, BaseModel):
parent_id = db.Column(db.Integer, db.ForeignKey("rt_power.id"), comment='父类编号')
icon = db.Column(db.String(128), comment='图标')
sort = db.Column(db.Integer, comment='排序')
create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
update_time = db.Column(db.DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')
enable = db.Column(db.Integer, comment='是否开启')
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,
}
+18 -2
View File
@@ -1,3 +1,5 @@
from flask_restful import fields
from applications.extensions import db
from ..base import BaseModel
@@ -7,9 +9,23 @@ class RightsRole(db.Model, BaseModel):
id = db.Column(db.Integer, primary_key=True, comment='角色ID')
name = db.Column(db.String(255), comment='角色名称')
code = db.Column(db.String(255), comment='角色标识')
enable = db.Column(db.Integer, comment='是否启用')
remark = db.Column(db.String(255), comment='备注')
enable = db.Column(db.Boolean, comment='是否启用')
comment = db.Column(db.String(255), comment='备注')
details = db.Column(db.String(255), comment='详情')
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,
}
+20 -3
View File
@@ -1,3 +1,4 @@
from flask_restful import fields
from applications.extensions import db
from ..base import BaseModel
@@ -7,10 +8,26 @@ class CompanyDepartment(db.Model, BaseModel):
id = db.Column(db.Integer, primary_key=True, comment="部门ID")
parent_id = db.Column(db.Integer, comment="父级编号")
dept_name = db.Column(db.String(50), comment="部门名称")
sort = db.Column(db.Integer, comment="排序")
leader = db.Column(db.String(50), comment="负责人")
phone = db.Column(db.String(20), comment="联系方式")
email = db.Column(db.String(50), comment="邮箱")
status = db.Column(db.Integer, comment='状态(1开启,0关闭)')
remark = db.Column(db.Text, comment="备注")
status = db.Column(db.Boolean, comment='状态(1开启,0关闭)')
comment = db.Column(db.Text, comment="备注")
address = db.Column(db.String(255), comment="详细地址")
sort = db.Column(db.Integer, comment="排序")
@staticmethod
def fields():
return {
'deptId': fields.Integer(attribute="id"),
'parentId': fields.Integer(attribute="parent_id"),
'deptName': fields.String(attribute="dept_name"),
'sort': fields.Integer,
'leader': fields.String,
'phone': fields.String,
'email': fields.String,
'status': fields.Boolean,
'comment': fields.String,
'address': fields.String,
'create_at': fields.DateTime
}
+20 -1
View File
@@ -1,5 +1,6 @@
from flask_login import UserMixin
from werkzeug.security import generate_password_hash, check_password_hash
from flask_restful import fields
from applications.extensions import db
from ..base import BaseModel
@@ -12,7 +13,7 @@ class CompanyUser(db.Model, UserMixin, BaseModel):
realname = db.Column(db.String(20), comment='真实名字')
mobile = db.Column(db.String(11), comment='电话号码')
avatar = db.Column(db.String(255), comment='头像', default="/static/admin/admin/images/avatar.jpg")
remark = db.Column(db.String(255), comment='备注')
comment = db.Column(db.String(255), comment='备注')
password_hash = db.Column(db.String(128), comment='哈希密码')
enable = db.Column(db.Integer, default=0, comment='启用')
dept_id = db.Column(db.Integer, comment='部门id')
@@ -24,3 +25,21 @@ class CompanyUser(db.Model, UserMixin, BaseModel):
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,
}