[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):
|
||||
from flask import request
|
||||
|
||||
try:
|
||||
token = list(filter(None, request.headers.get("Authorization").split(" ")))[-1]
|
||||
except AttributeError:
|
||||
|
@ -30,6 +31,7 @@ def login_required(permission=None):
|
|||
Returns:
|
||||
Wrapped function with login (and permission) guard
|
||||
"""
|
||||
|
||||
def wrap(func):
|
||||
@wraps(func)
|
||||
def wrapped_f(*args, **kwargs):
|
||||
|
|
|
@ -5,6 +5,7 @@ class Hook(object):
|
|||
"""Decorator for Hooks
|
||||
Use to decorate system hooks where plugins should be able to hook in
|
||||
"""
|
||||
|
||||
def __init__(self, function):
|
||||
self.function = function
|
||||
|
||||
|
@ -16,6 +17,7 @@ class Hook(object):
|
|||
|
||||
class HookCall(object):
|
||||
"""Decorator for functions to be called if a Hook is called"""
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
|
|
|
@ -3,12 +3,19 @@ from sqlalchemy.types import DateTime, TypeDecorator
|
|||
|
||||
|
||||
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):
|
||||
"""Serialize class to dict
|
||||
Returns:
|
||||
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:
|
||||
key, value = d.popitem()
|
||||
return value
|
||||
|
|
|
@ -5,6 +5,7 @@ import argparse
|
|||
|
||||
def install(arguments):
|
||||
from flaschengeist.app import create_app, install_all
|
||||
|
||||
app = create_app()
|
||||
with app.app_context():
|
||||
install_all()
|
||||
|
@ -20,6 +21,7 @@ def run(arguments):
|
|||
else:
|
||||
try:
|
||||
import bjoern
|
||||
|
||||
bjoern.run(app, arguments.host, arguments.port, reuse_port=True)
|
||||
except ImportError:
|
||||
app.run(arguments.host, arguments.port, debug=False)
|
||||
|
@ -56,7 +58,11 @@ def export(arguments):
|
|||
and not mod[0].startswith("_")
|
||||
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:
|
||||
key, value = d.popitem()
|
||||
classes[mod[0]] = value[1]
|
||||
|
|
Loading…
Reference in New Issue