[System] Some cleanup
This commit is contained in:
parent
2f9446be2f
commit
36c4027c5d
|
@ -7,6 +7,7 @@ from flaschengeist.controller import sessionController
|
||||||
|
|
||||||
def extract_session(permission=None):
|
def extract_session(permission=None):
|
||||||
from flask import request
|
from flask import request
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token = list(filter(None, request.headers.get("Authorization").split(" ")))[-1]
|
token = list(filter(None, request.headers.get("Authorization").split(" ")))[-1]
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
@ -30,6 +31,7 @@ def login_required(permission=None):
|
||||||
Returns:
|
Returns:
|
||||||
Wrapped function with login (and permission) guard
|
Wrapped function with login (and permission) guard
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def wrap(func):
|
def wrap(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def wrapped_f(*args, **kwargs):
|
def wrapped_f(*args, **kwargs):
|
||||||
|
|
|
@ -5,6 +5,7 @@ class Hook(object):
|
||||||
"""Decorator for Hooks
|
"""Decorator for Hooks
|
||||||
Use to decorate system hooks where plugins should be able to hook in
|
Use to decorate system hooks where plugins should be able to hook in
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, function):
|
def __init__(self, function):
|
||||||
self.function = function
|
self.function = function
|
||||||
|
|
||||||
|
@ -16,6 +17,7 @@ class Hook(object):
|
||||||
|
|
||||||
class HookCall(object):
|
class HookCall(object):
|
||||||
"""Decorator for functions to be called if a Hook is called"""
|
"""Decorator for functions to be called if a Hook is called"""
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
|
||||||
|
|
|
@ -3,12 +3,19 @@ from sqlalchemy.types import DateTime, TypeDecorator
|
||||||
|
|
||||||
|
|
||||||
class ModelSerializeMixin:
|
class ModelSerializeMixin:
|
||||||
|
"""Mixin class used for models to serialize them automatically
|
||||||
|
Ignores private and protected members as well as members marked as not to publish (name ends with _)
|
||||||
|
"""
|
||||||
def serialize(self):
|
def serialize(self):
|
||||||
"""Serialize class to dict
|
"""Serialize class to dict
|
||||||
Returns:
|
Returns:
|
||||||
Dict of all not private or protected annotated member variables.
|
Dict of all not private or protected annotated member variables.
|
||||||
"""
|
"""
|
||||||
d = {param: getattr(self, param) for param in self.__class__.__annotations__ if not param.startswith("_")}
|
d = {
|
||||||
|
param: getattr(self, param)
|
||||||
|
for param in self.__class__.__annotations__
|
||||||
|
if not param.startswith("_") and not param.endswith("_")
|
||||||
|
}
|
||||||
if len(d) == 1:
|
if len(d) == 1:
|
||||||
key, value = d.popitem()
|
key, value = d.popitem()
|
||||||
return value
|
return value
|
||||||
|
|
|
@ -5,6 +5,7 @@ import argparse
|
||||||
|
|
||||||
def install(arguments):
|
def install(arguments):
|
||||||
from flaschengeist.app import create_app, install_all
|
from flaschengeist.app import create_app, install_all
|
||||||
|
|
||||||
app = create_app()
|
app = create_app()
|
||||||
with app.app_context():
|
with app.app_context():
|
||||||
install_all()
|
install_all()
|
||||||
|
@ -20,6 +21,7 @@ def run(arguments):
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
import bjoern
|
import bjoern
|
||||||
|
|
||||||
bjoern.run(app, arguments.host, arguments.port, reuse_port=True)
|
bjoern.run(app, arguments.host, arguments.port, reuse_port=True)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
app.run(arguments.host, arguments.port, debug=False)
|
app.run(arguments.host, arguments.port, debug=False)
|
||||||
|
@ -34,7 +36,7 @@ def export(arguments):
|
||||||
def pytype(cls):
|
def pytype(cls):
|
||||||
if isinstance(cls, list):
|
if isinstance(cls, list):
|
||||||
return "", "Array<{}>".format(pytype(cls[0])[1])
|
return "", "Array<{}>".format(pytype(cls[0])[1])
|
||||||
#if typing.get_origin(cls) is typing.Optional:
|
# if typing.get_origin(cls) is typing.Optional:
|
||||||
# return "?", pytype(typing.get_args(cls)[1])
|
# return "?", pytype(typing.get_args(cls)[1])
|
||||||
mapper = {"str": "string", "int": "number", "float": "number", "datetime": "Date"}
|
mapper = {"str": "string", "int": "number", "float": "number", "datetime": "Date"}
|
||||||
if hasattr(cls, "__name__"):
|
if hasattr(cls, "__name__"):
|
||||||
|
@ -56,7 +58,11 @@ def export(arguments):
|
||||||
and not mod[0].startswith("_")
|
and not mod[0].startswith("_")
|
||||||
and hasattr(mod[1], "__annotations__")
|
and hasattr(mod[1], "__annotations__")
|
||||||
):
|
):
|
||||||
d = {param: pytype(ptype) for param, ptype in mod[1].__annotations__.items() if not param.startswith("_")}
|
d = {
|
||||||
|
param: pytype(ptype)
|
||||||
|
for param, ptype in mod[1].__annotations__.items()
|
||||||
|
if not param.startswith("_") and not param.endswith("_")
|
||||||
|
}
|
||||||
if len(d) == 1:
|
if len(d) == 1:
|
||||||
key, value = d.popitem()
|
key, value = d.popitem()
|
||||||
classes[mod[0]] = value[1]
|
classes[mod[0]] = value[1]
|
||||||
|
|
Loading…
Reference in New Issue