This commit is contained in:
resonate
2022-01-23 16:03:40 +08:00
parent ef8044ea22
commit a3c61d3291
15 changed files with 220 additions and 54 deletions
+2 -4
View File
@@ -2,7 +2,6 @@ import datetime
from entrance.extensions import db from entrance.extensions import db
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy import Table
from sqlalchemy import ForeignKey from sqlalchemy import ForeignKey
from sqlalchemy.orm import backref from sqlalchemy.orm import backref
from marshmallow_sqlalchemy import SQLAlchemyAutoSchema from marshmallow_sqlalchemy import SQLAlchemyAutoSchema
@@ -38,7 +37,7 @@ class CurdModel(BaseModel):
Column = db.Column Column = db.Column
Table = Table Table = db.Table
relationship = relationship relationship = relationship
ForeignKey = ForeignKey ForeignKey = ForeignKey
backref = backref backref = backref
@@ -87,5 +86,4 @@ Enum = db.Enum
ARRAY = db.ARRAY ARRAY = db.ARRAY
JSON = db.JSON JSON = db.JSON
SQLAlchemyAutoSchema = SQLAlchemyAutoSchema
SQLAlchemyAutoSchema=SQLAlchemyAutoSchema
+3 -3
View File
@@ -1,9 +1,9 @@
from flask_mail import Message from flask_mail import Message
from applications.extensions.init_mail import mail
# send_mail(subject='title', recipients=['123@qq.com'], content='body') # send_mail(subject='title', recipients=['123@qq.com'], content='body')
from entrance.extend.mail import mail
def send_mail(subject, recipients, content): def send_mail(subject, recipients, content):
try: try:
message = Message(subject=subject, recipients=recipients, body=content) message = Message(subject=subject, recipients=recipients, body=content)
+1 -13
View File
@@ -4,21 +4,8 @@ from flask.views import MethodViewType, MethodView
class Blueprint(FlaskBlueprint): class Blueprint(FlaskBlueprint):
# Order in which the methods are presented in the spec
HTTP_METHODS = ["OPTIONS", "HEAD", "GET", "POST", "PUT", "PATCH", "DELETE"]
DEFAULT_LOCATION_CONTENT_TYPE_MAPPING = {
"json": "application/json",
"form": "application/x-www-form-urlencoded",
"files": "multipart/form-data",
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.description = kwargs.pop("description", "")
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._endpoints = [] self._endpoints = []
@@ -75,5 +62,6 @@ class Blueprint(FlaskBlueprint):
for bp in bp_lists: for bp in bp_lists:
self.register_blueprint(bp) self.register_blueprint(bp)
class View(MethodView): class View(MethodView):
pass pass
+12 -2
View File
@@ -1,7 +1,17 @@
from flask_migrate import Migrate from flask_migrate import Migrate
from entrance.extend.orm import db from entrance.extend.orm import db
# from entrance.models import model_lists <-- 这一行不要删除 # from entrance.models import model_lists
from entrance.models import model_lists from modules.sys.models.user_role import user_role
from modules.sys.models.role_power import role_power
from modules.sys.models.dict import DictType, DictData
from modules.sys.models.admin_log import AdminLog
from modules.sys.models.photo import Photo
from modules.sys.models.power import Power
from modules.sys.models.role import Role
from modules.sys.models.dept import Dept
from modules.sys.models.user import User
migrate = Migrate(db=db, directory='entrance/migrations') migrate = Migrate(db=db, directory='entrance/migrations')
-3
View File
@@ -1,6 +1,5 @@
from flask import Flask from flask import Flask
from entrance.extend.mail import mail
from entrance.extend.orm import db from entrance.extend.orm import db
from entrance.extend.migrate import migrate from entrance.extend.migrate import migrate
@@ -8,5 +7,3 @@ from entrance.extend.migrate import migrate
def init_extensions(app: Flask): def init_extensions(app: Flask):
db.init_app(app) db.init_app(app)
migrate.init_app(app) migrate.init_app(app)
mail.init_app(app)
@@ -0,0 +1,168 @@
"""empty message
Revision ID: 8293d5eb9040
Revises: d51040631f21
Create Date: 2022-01-23 15:56:22.001914
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import mysql
# revision identifiers, used by Alembic.
revision = '8293d5eb9040'
down_revision = 'd51040631f21'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('sys_admin_log',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('method', sa.String(length=10), nullable=True),
sa.Column('uid', sa.Integer(), nullable=True),
sa.Column('url', sa.String(length=255), nullable=True),
sa.Column('desc', sa.Text(), nullable=True),
sa.Column('ip', sa.String(length=255), nullable=True),
sa.Column('success', sa.Integer(), nullable=True),
sa.Column('user_agent', sa.Text(), nullable=True),
sa.Column('create_time', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('sys_dept',
sa.Column('id', sa.Integer(), nullable=False, comment='部门ID'),
sa.Column('parent_id', sa.Integer(), nullable=True, comment='父级编号'),
sa.Column('dept_name', sa.String(length=50), nullable=True, comment='部门名称'),
sa.Column('sort', sa.Integer(), nullable=True, comment='排序'),
sa.Column('leader', sa.String(length=50), nullable=True, comment='负责人'),
sa.Column('phone', sa.String(length=20), nullable=True, comment='联系方式'),
sa.Column('email', sa.String(length=50), nullable=True, comment='邮箱'),
sa.Column('status', sa.Integer(), nullable=True, comment='状态(1开启,0关闭)'),
sa.Column('remark', sa.Text(), nullable=True, comment='备注'),
sa.Column('address', sa.String(length=255), nullable=True, comment='详细地址'),
sa.Column('create_at', sa.DateTime(), nullable=True, comment='创建时间'),
sa.Column('update_at', sa.DateTime(), nullable=True, comment='创建时间'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('sys_dict_data',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('data_label', sa.String(length=255), nullable=True, comment='字典类型名称'),
sa.Column('data_value', sa.String(length=255), nullable=True, comment='字典类型标识'),
sa.Column('type_code', sa.String(length=255), nullable=True, comment='字典类型描述'),
sa.Column('is_default', sa.Integer(), nullable=True, comment='是否默认'),
sa.Column('enable', sa.Integer(), nullable=True, comment='是否开启'),
sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'),
sa.Column('create_time', sa.DateTime(), nullable=True, comment='创建时间'),
sa.Column('update_time', sa.DateTime(), nullable=True, comment='更新时间'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('sys_dict_type',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('type_name', sa.String(length=255), nullable=True, comment='字典类型名称'),
sa.Column('type_code', sa.String(length=255), nullable=True, comment='字典类型标识'),
sa.Column('description', sa.String(length=255), nullable=True, comment='字典类型描述'),
sa.Column('enable', sa.Integer(), nullable=True, comment='是否开启'),
sa.Column('create_time', sa.DateTime(), nullable=True, comment='创建时间'),
sa.Column('update_time', sa.DateTime(), nullable=True, comment='更新时间'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('sys_photo',
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('name', sa.String(length=255), nullable=False),
sa.Column('href', sa.String(length=255), nullable=True),
sa.Column('mime', sa.CHAR(length=50), nullable=False),
sa.Column('size', sa.CHAR(length=30), nullable=False),
sa.Column('create_time', sa.DateTime(), nullable=True),
sa.PrimaryKeyConstraint('id')
)
op.create_table('sys_power',
sa.Column('id', sa.Integer(), nullable=False, comment='权限编号'),
sa.Column('name', sa.String(length=255), nullable=True, comment='权限名称'),
sa.Column('type', sa.String(length=1), nullable=True, comment='权限类型'),
sa.Column('code', sa.String(length=30), nullable=True, comment='权限标识'),
sa.Column('url', sa.String(length=255), nullable=True, comment='权限路径'),
sa.Column('open_type', sa.String(length=10), nullable=True, comment='打开方式'),
sa.Column('parent_id', sa.Integer(), nullable=True, comment='父类编号'),
sa.Column('icon', sa.String(length=128), nullable=True, comment='图标'),
sa.Column('sort', sa.Integer(), nullable=True, comment='排序'),
sa.Column('create_time', sa.DateTime(), nullable=True, comment='创建时间'),
sa.Column('update_time', sa.DateTime(), nullable=True, comment='更新时间'),
sa.Column('enable', sa.Integer(), nullable=True, comment='是否开启'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('sys_role',
sa.Column('id', sa.Integer(), nullable=False, comment='角色ID'),
sa.Column('name', sa.String(length=255), nullable=True, comment='角色名称'),
sa.Column('code', sa.String(length=255), nullable=True, comment='角色标识'),
sa.Column('enable', sa.Integer(), nullable=True, comment='是否启用'),
sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'),
sa.Column('details', sa.String(length=255), nullable=True, comment='详情'),
sa.Column('sort', sa.Integer(), nullable=True, comment='排序'),
sa.Column('create_time', sa.DateTime(), nullable=True, comment='创建时间'),
sa.Column('update_time', sa.DateTime(), nullable=True, comment='更新时间'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('sys_user',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='用户ID'),
sa.Column('username', sa.String(length=20), nullable=True, comment='用户名'),
sa.Column('realname', sa.String(length=20), nullable=True, comment='真实名字'),
sa.Column('avatar', sa.String(length=255), nullable=True, comment='头像'),
sa.Column('remark', sa.String(length=255), nullable=True, comment='备注'),
sa.Column('password_hash', sa.String(length=128), nullable=True, comment='哈希密码'),
sa.Column('enable', sa.Integer(), nullable=True, comment='启用'),
sa.Column('dept_id', sa.Integer(), nullable=True, comment='部门id'),
sa.Column('create_at', sa.DateTime(), nullable=True, comment='创建时间'),
sa.Column('update_at', sa.DateTime(), nullable=True, comment='创建时间'),
sa.PrimaryKeyConstraint('id')
)
op.create_table('sys_role_power',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='标识'),
sa.Column('power_id', sa.Integer(), nullable=True, comment='用户编号'),
sa.Column('role_id', sa.Integer(), nullable=True, comment='角色编号'),
sa.ForeignKeyConstraint(['power_id'], ['sys_power.id'], ),
sa.ForeignKeyConstraint(['role_id'], ['sys_role.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('sys_user_role',
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False, comment='标识'),
sa.Column('user_id', sa.Integer(), nullable=True, comment='用户编号'),
sa.Column('role_id', sa.Integer(), nullable=True, comment='角色编号'),
sa.ForeignKeyConstraint(['role_id'], ['sys_role.id'], ),
sa.ForeignKeyConstraint(['user_id'], ['sys_user.id'], ),
sa.PrimaryKeyConstraint('id')
)
op.drop_table('admin_test')
op.drop_table('admin_user')
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('admin_user',
sa.Column('id', mysql.INTEGER(display_width=11), autoincrement=True, nullable=False, comment='用户ID'),
sa.Column('username', mysql.VARCHAR(collation='utf8mb4_general_ci', length=20), nullable=True, comment='用户名'),
sa.PrimaryKeyConstraint('id'),
mysql_collate='utf8mb4_general_ci',
mysql_default_charset='utf8mb4',
mysql_engine='MyISAM'
)
op.create_table('admin_test',
sa.Column('id', mysql.INTEGER(display_width=11), autoincrement=True, nullable=False, comment='ID'),
sa.Column('name', mysql.VARCHAR(collation='utf8mb4_general_ci', length=20), nullable=True, comment=''),
sa.PrimaryKeyConstraint('id'),
mysql_collate='utf8mb4_general_ci',
mysql_default_charset='utf8mb4',
mysql_engine='MyISAM'
)
op.drop_table('sys_user_role')
op.drop_table('sys_role_power')
op.drop_table('sys_user')
op.drop_table('sys_role')
op.drop_table('sys_power')
op.drop_table('sys_photo')
op.drop_table('sys_dict_type')
op.drop_table('sys_dict_data')
op.drop_table('sys_dept')
op.drop_table('sys_admin_log')
# ### end Alembic commands ###
+14 -10
View File
@@ -1,21 +1,25 @@
from modules.sys.models.admin_dept import Dept
from modules.sys.models.admin_dict import DictType, DictData from modules.sys.models.user_role import user_role
from modules.sys.models.role_power import role_power
from modules.sys.models.dict import DictType, DictData
from modules.sys.models.admin_log import AdminLog from modules.sys.models.admin_log import AdminLog
from modules.sys.models.admin_photo import Photo from modules.sys.models.photo import Photo
from modules.sys.models.admin_power import Power from modules.sys.models.power import Power
from modules.sys.models.admin_role import Role from modules.sys.models.role import Role
from modules.sys.models.admin_role_power import role_power from modules.sys.models.dept import Dept
from modules.sys.models.admin_user import User
from modules.sys.models.admin_user_role import user_role from modules.sys.models.user import User
model_lists: list = [ model_lists: list = [
role_power,
user_role,
Dept, Dept,
DictType, DictData, DictType, DictData,
AdminLog, AdminLog,
Photo, Photo,
Power, Power,
Role, Role,
role_power,
User, User,
user_role
] ]
@@ -1,5 +1,5 @@
import datetime import datetime
from common.model import BaseModel, Column, String, Integer, DateTime, relationship, SQLAlchemyAutoSchema from common.model import BaseModel, Column, String, Integer, DateTime, relationship, SQLAlchemyAutoSchema, backref
class Role(BaseModel): class Role(BaseModel):
@@ -13,7 +13,8 @@ class Role(BaseModel):
sort = Column(Integer, comment='排序') sort = Column(Integer, comment='排序')
create_time = Column(DateTime, default=datetime.datetime.now, comment='创建时间') create_time = Column(DateTime, default=datetime.datetime.now, comment='创建时间')
update_time = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间') update_time = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='更新时间')
power = relationship('Power', secondary="admin_role_power", backref=backref('role')) power = relationship('Power', secondary="sys_role_power", backref=backref('role'))
class RoleSchema(SQLAlchemyAutoSchema): class RoleSchema(SQLAlchemyAutoSchema):
class Meta: class Meta:
@@ -3,6 +3,6 @@ from common.model import Column, Table, Integer, ForeignKey
role_power = Table( role_power = Table(
"sys_role_power", "sys_role_power",
Column("id", Integer, primary_key=True, autoincrement=True, comment='标识'), Column("id", Integer, primary_key=True, autoincrement=True, comment='标识'),
Column("power_id", Integer, ForeignKey("admin_power.id"), comment='用户编号'), Column("power_id", Integer, ForeignKey("sys_power.id"), comment='用户编号'),
Column("role_id", Integer, ForeignKey("admin_role.id"), comment='角色编号'), Column("role_id", Integer, ForeignKey("sys_role.id"), comment='角色编号'),
) )
@@ -17,7 +17,7 @@ class User(BaseModel, UserMixin):
dept_id = Column(Integer, comment='部门id') dept_id = Column(Integer, comment='部门id')
create_at = Column(DateTime, default=datetime.datetime.now, comment='创建时间') create_at = Column(DateTime, default=datetime.datetime.now, comment='创建时间')
update_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='创建时间') update_at = Column(DateTime, default=datetime.datetime.now, onupdate=datetime.datetime.now, comment='创建时间')
role = relationship('Role', secondary="admin_user_role", backref=backref('user'), lazy='dynamic') role = relationship('Role', secondary="sys_user_role", backref=backref('user'), lazy='dynamic')
def set_password(self, password): def set_password(self, password):
self.password_hash = generate_password_hash(password) self.password_hash = generate_password_hash(password)
@@ -3,6 +3,6 @@ from common.model import Table, Column, Integer, ForeignKey
user_role = Table( user_role = Table(
"sys_user_role", "sys_user_role",
Column("id", Integer, primary_key=True, autoincrement=True, comment='标识'), Column("id", Integer, primary_key=True, autoincrement=True, comment='标识'),
Column("user_id", Integer, ForeignKey("admin_user.id"), comment='用户编号'), Column("user_id", Integer, ForeignKey("sys_user.id"), comment='用户编号'),
Column("role_id", Integer, ForeignKey("admin_role.id"), comment='角色编号'), Column("role_id", Integer, ForeignKey("sys_role.id"), comment='角色编号'),
) )