From 72e3324141fccd3340e59d6d072ce6d80a4a4d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn-Michael=20Miehe?= <40151420+ldericher@users.noreply.github.com> Date: Fri, 9 Sep 2022 03:16:26 +0000 Subject: [PATCH] default settings values handling --- api/ovdashboard_api/settings.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/api/ovdashboard_api/settings.py b/api/ovdashboard_api/settings.py index 426c7b7..497baf9 100644 --- a/api/ovdashboard_api/settings.py +++ b/api/ovdashboard_api/settings.py @@ -31,16 +31,6 @@ class DavSettings(BaseModel): return f"{self.protocol}://{self.host}{self.path}" - @classmethod - @property - def default(cls) -> "DavSettings": - return cls( - protocol="https", - host="example.com", - username="ovdashboard", - password="secret", - ) - class Settings(BaseSettings): """ @@ -84,15 +74,20 @@ class Settings(BaseSettings): if key not in values: values[key] = {} - default_dav = DavSettings.default.dict() + default_dav = DavSettings( + protocol="https", + host="example.com", + username="ovdashboard", + password="secret", + ).dict() for key in default_dav: # if "webdav" value is not specified, use default - if key not in values["webdav"]: + if key not in values["webdav"] or values["webdav"][key] is None: values["webdav"][key] = default_dav[key] # if "caldav" value is not specified, use "webdav" value - if key not in values["caldav"]: + if key not in values["caldav"] or values["caldav"][key] is None: values["caldav"][key] = values["webdav"][key] # add default "path"s if None