From 36c4027c5dd1c631bf6ca84890b6ad9c916e1888 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Sun, 1 Nov 2020 18:37:08 +0100 Subject: [PATCH] [System] Some cleanup --- flaschengeist/decorator.py | 2 ++ flaschengeist/hook.py | 2 ++ flaschengeist/models/__init__.py | 9 ++++++++- run_flaschengeist | 10 ++++++++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/flaschengeist/decorator.py b/flaschengeist/decorator.py index 822000e..e29fb4a 100644 --- a/flaschengeist/decorator.py +++ b/flaschengeist/decorator.py @@ -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): diff --git a/flaschengeist/hook.py b/flaschengeist/hook.py index 067d4e5..0af84f3 100644 --- a/flaschengeist/hook.py +++ b/flaschengeist/hook.py @@ -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 diff --git a/flaschengeist/models/__init__.py b/flaschengeist/models/__init__.py index 415ffee..0346a2a 100644 --- a/flaschengeist/models/__init__.py +++ b/flaschengeist/models/__init__.py @@ -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 diff --git a/run_flaschengeist b/run_flaschengeist index 1ee770f..f9951e9 100644 --- a/run_flaschengeist +++ b/run_flaschengeist @@ -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) @@ -34,7 +36,7 @@ def export(arguments): def pytype(cls): if isinstance(cls, list): 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]) mapper = {"str": "string", "int": "number", "float": "number", "datetime": "Date"} if hasattr(cls, "__name__"): @@ -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]