[System] Some cleanup

This commit is contained in:
Ferdinand Thiessen 2020-11-01 18:37:08 +01:00
parent 2f9446be2f
commit 36c4027c5d
4 changed files with 20 additions and 3 deletions

View File

@ -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):

View File

@ -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

View File

@ -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

View File

@ -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]