[chore] Minor cleanup

This commit is contained in:
Ferdinand Thiessen 2021-03-18 12:20:17 +01:00
parent 466efcf9e7
commit 900b5efff5
5 changed files with 27 additions and 17 deletions

View File

@ -14,8 +14,11 @@ class ModelSerializeMixin:
return False
import typing
if typing.get_origin(self.__class__.__annotations__[param]) is typing.Union and \
typing.get_args(self.__class__.__annotations__[param])[1] is None:
if (
typing.get_origin(self.__class__.__annotations__[param]) is typing.Union
and isinstance(typing.get_args(self.__class__.__annotations__[param])[1], type(None))
):
return getattr(self, param) is None
def serialize(self):

View File

@ -62,9 +62,11 @@ class Plugin:
Value stored in database (native python)
"""
try:
setting = _PluginSetting.query\
.filter(_PluginSetting.plugin == self._plugin_name)\
.filter(_PluginSetting.name == name).one()
setting = (
_PluginSetting.query.filter(_PluginSetting.plugin == self._plugin_name)
.filter(_PluginSetting.name == name)
.one()
)
return setting.value
except sqlalchemy.orm.exc.NoResultFound:
if "default" in kwargs:
@ -78,9 +80,11 @@ class Plugin:
name: String identifying the setting
value: Value to be stored
"""
setting = _PluginSetting.query \
.filter(_PluginSetting.plugin == self._plugin_name) \
.filter(_PluginSetting.name == name).one_or_none()
setting = (
_PluginSetting.query.filter(_PluginSetting.plugin == self._plugin_name)
.filter(_PluginSetting.name == name)
.one_or_none()
)
if setting is not None:
setting.value = value
else:

View File

@ -23,10 +23,12 @@ class AuthPlain(AuthPlugin):
self.modify_user(admin, None, "admin")
db.session.add(admin)
db.session.commit()
logger.warning("New administrator user was added, please change the password or remove it before going into"
logger.warning(
"New administrator user was added, please change the password or remove it before going into"
"production mode. Initial credentials:\n"
"name: admin\n"
"password: admin")
"password: admin"
)
def login(self, user: User, password: str):
if user.has_attribute("password"):

View File

@ -1,7 +1,10 @@
import datetime
from backports.datetime_fromisoformat import MonkeyPatch
import sys
MonkeyPatch.patch_fromisoformat()
if sys.version_info < (3, 7):
from backports.datetime_fromisoformat import MonkeyPatch
MonkeyPatch.patch_fromisoformat()
def from_iso_format(date_str):

View File

@ -10,7 +10,7 @@ setup(
packages=find_packages(),
package_data={"": ["*.toml"]},
scripts=["run_flaschengeist"],
python_requires=">=3.6",
python_requires=">=3.7",
install_requires=[
"Flask >= 1.1",
"toml",
@ -19,8 +19,6 @@ setup(
"flask_sqlalchemy",
"flask_cors",
"werkzeug",
# Needed for python < 3.7
"backports-datetime-fromisoformat",
],
extras_require={"ldap": ["flask_ldapconn", "ldap3"], "test": ["pytest", "coverage"]},
entry_points={