[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 return False
import typing 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 return getattr(self, param) is None
def serialize(self): def serialize(self):

View File

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

View File

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

View File

@ -1,7 +1,10 @@
import datetime 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): def from_iso_format(date_str):

View File

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