default settings values handling

This commit is contained in:
Jörn-Michael Miehe 2022-09-09 03:16:26 +00:00
parent 6b8d6f8bc7
commit 72e3324141

View file

@ -31,16 +31,6 @@ class DavSettings(BaseModel):
return f"{self.protocol}://{self.host}{self.path}" 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): class Settings(BaseSettings):
""" """
@ -84,15 +74,20 @@ class Settings(BaseSettings):
if key not in values: if key not in values:
values[key] = {} 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: for key in default_dav:
# if "webdav" value is not specified, use default # 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] values["webdav"][key] = default_dav[key]
# if "caldav" value is not specified, use "webdav" value # 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] values["caldav"][key] = values["webdav"][key]
# add default "path"s if None # add default "path"s if None