2022/1/22
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
import datetime
|
||||
|
||||
from entrance.extensions import db
|
||||
|
||||
|
||||
class BaseModel(db.Model):
|
||||
__abstract__ = True
|
||||
|
||||
# insert and update
|
||||
def save(self):
|
||||
db.session.add(self)
|
||||
db.session.commit()
|
||||
|
||||
# delete
|
||||
def delete(self):
|
||||
db.session.delete(self)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
class CommonModel(BaseModel):
|
||||
__abstract__ = True
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='用户ID')
|
||||
create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
|
||||
update_time = db.Column(db.DateTime, onupdate=datetime.datetime.now, comment='更新时间')
|
||||
|
||||
|
||||
class CurdModel(BaseModel):
|
||||
__abstract__ = True
|
||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True, comment='用户ID')
|
||||
create_time = db.Column(db.DateTime, default=datetime.datetime.now, comment='创建时间')
|
||||
update_time = db.Column(db.DateTime, onupdate=datetime.datetime.now, comment='更新时间')
|
||||
delete_at = db.Column(db.DateTime, comment='删除时间')
|
||||
|
||||
|
||||
Column = db.Column
|
||||
|
||||
TypeDecorator = db.TypeDecorator
|
||||
INT = db.INT
|
||||
CHAR = db.CHAR
|
||||
VARCHAR = db.VARCHAR
|
||||
NCHAR = db.NCHAR
|
||||
NVARCHAR = db.NVARCHAR
|
||||
TEXT = db.TEXT
|
||||
Text = db.Text
|
||||
FLOAT = db.FLOAT
|
||||
NUMERIC = db.NUMERIC
|
||||
REAL = db.REAL
|
||||
DECIMAL = db.DECIMAL
|
||||
TIMESTAMP = db.TIMESTAMP
|
||||
DATETIME = db.DATETIME
|
||||
CLOB = db.CLOB
|
||||
BLOB = db.BLOB
|
||||
BINARY = db.BINARY
|
||||
VARBINARY = db.VARBINARY
|
||||
BOOLEAN = db.BOOLEAN
|
||||
BIGINT = db.BIGINT
|
||||
SMALLINT = db.SMALLINT
|
||||
INTEGER = db.INTEGER
|
||||
DATE = db.DATE
|
||||
TIME = db.TIME
|
||||
TupleType = db.TupleType
|
||||
String = db.String
|
||||
Integer = db.Integer
|
||||
SmallInteger = db.SmallInteger
|
||||
BigInteger = db.BigInteger
|
||||
Numeric = db.Numeric
|
||||
Float = db.Float
|
||||
DateTime = db.DateTime
|
||||
Date = db.Date
|
||||
Time = db.Time
|
||||
LargeBinary = db.LargeBinary
|
||||
Boolean = db.Boolean
|
||||
Unicode = db.Unicode
|
||||
UnicodeText = db.UnicodeText
|
||||
PickleType = db.PickleType
|
||||
Interval = db.Interval
|
||||
Enum = db.Enum
|
||||
ARRAY = db.ARRAY
|
||||
JSON = db.JSON
|
||||
+79
-1
@@ -1 +1,79 @@
|
||||
from flask_restx import Resource, Namespace
|
||||
from flask import Blueprint as FlaskBlueprint
|
||||
from flask.views import MethodViewType, MethodView
|
||||
|
||||
|
||||
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):
|
||||
|
||||
self.description = kwargs.pop("description", "")
|
||||
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
self._endpoints = []
|
||||
|
||||
def add_url_rule(
|
||||
self,
|
||||
rule,
|
||||
endpoint=None,
|
||||
view_func=None,
|
||||
provide_automatic_options=None,
|
||||
*,
|
||||
parameters=None,
|
||||
tags=None,
|
||||
**options,
|
||||
):
|
||||
|
||||
if view_func is None:
|
||||
raise TypeError("view_func must be provided")
|
||||
|
||||
if endpoint is None:
|
||||
endpoint = view_func.__name__
|
||||
|
||||
# Ensure endpoint name is unique
|
||||
# - to avoid a name clash when registering a MethodView
|
||||
# - to use it as a key internally in endpoint -> doc mapping
|
||||
if endpoint in self._endpoints:
|
||||
endpoint = f"{endpoint}_{len(self._endpoints)}"
|
||||
self._endpoints.append(endpoint)
|
||||
|
||||
if isinstance(view_func, MethodViewType):
|
||||
func = view_func.as_view(endpoint)
|
||||
else:
|
||||
func = view_func
|
||||
|
||||
# Add URL rule in Flask and store endpoint documentation
|
||||
super().add_url_rule(rule, endpoint, func, **options)
|
||||
|
||||
def route(self, rule, *, parameters=None, tags=None, **options):
|
||||
"""Decorator to register view function in application and documentation
|
||||
|
||||
Calls :meth:`add_url_rule <Blueprint.add_url_rule>`.
|
||||
"""
|
||||
|
||||
def decorator(func):
|
||||
endpoint = options.pop("endpoint", None)
|
||||
self.add_url_rule(
|
||||
rule, endpoint, func, parameters=parameters, tags=tags, **options
|
||||
)
|
||||
return func
|
||||
|
||||
return decorator
|
||||
|
||||
def register_child_bp(self, bp_lists):
|
||||
for bp in bp_lists:
|
||||
self.register_blueprint(bp)
|
||||
|
||||
class View(MethodView):
|
||||
pass
|
||||
Reference in New Issue
Block a user