From 53c39f4f920e6c31921e45e9fb203f50e5a48ac7 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Thu, 12 Nov 2020 00:12:52 +0100 Subject: [PATCH] [System] Added util for 201&204 HTTP response and some code formatting --- flaschengeist/models/user.py | 4 +--- flaschengeist/plugins/users/__init__.py | 4 ++-- flaschengeist/utils/HTTP.py | 11 +++++++++++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/flaschengeist/models/user.py b/flaschengeist/models/user.py index ae55369..51aefaf 100644 --- a/flaschengeist/models/user.py +++ b/flaschengeist/models/user.py @@ -27,9 +27,7 @@ class Role(db.Model, ModelSerializeMixin): __tablename__ = "role" id: int = db.Column(db.Integer, primary_key=True) name: str = db.Column(db.String(30), unique=True) - permissions: [Permission] = db.relationship( - "Permission", secondary=role_permission_association_table - ) + permissions: [Permission] = db.relationship("Permission", secondary=role_permission_association_table) class User(db.Model, ModelSerializeMixin): diff --git a/flaschengeist/plugins/users/__init__.py b/flaschengeist/plugins/users/__init__.py index ef7a7d7..0dfab0c 100644 --- a/flaschengeist/plugins/users/__init__.py +++ b/flaschengeist/plugins/users/__init__.py @@ -87,8 +87,8 @@ def get_user(userid, current_session): logger.debug("Get information of user {{ {} }}".format(userid)) user: User = userController.get_user(userid) serial = user.serialize() - if (userid == current_session._user.userid): - serial['permissions'] = user.get_permissions() + if userid == current_session._user.userid: + serial["permissions"] = user.get_permissions() return jsonify(serial) diff --git a/flaschengeist/utils/HTTP.py b/flaschengeist/utils/HTTP.py index e69de29..8fe57a9 100644 --- a/flaschengeist/utils/HTTP.py +++ b/flaschengeist/utils/HTTP.py @@ -0,0 +1,11 @@ +from http.client import NO_CONTENT, CREATED + +from flask import make_response, jsonify + + +def no_content(): + return make_response(jsonify(""), NO_CONTENT) + + +def created(obj=None): + return make_response(jsonify(obj if obj is not None else ""), CREATED)