Mercurial > kallithea
changeset 8660:9398244a2525
model: stop using 'Optional' class in Setting.create_or_update()
The 'Optional' class can help to identify whether a value is set by the
caller or a default value.
But if you can make the assumption that the caller will never specify a
'None' value as 'real' value, then the Optional class is not really
necessary.
As this usage in the Setting class is the only remaining usage of
'Optional', it does not seem worth it to keep it.
author | Thomas De Schampheleire <thomas.de_schampheleire@nokia.com> |
---|---|
date | Fri, 09 Oct 2020 20:07:46 +0200 |
parents | 0f3fbd5fb9ea |
children | 1394d16cc82a |
files | kallithea/model/db.py |
diffstat | 1 files changed, 8 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/model/db.py Fri Oct 09 19:45:13 2020 +0200 +++ b/kallithea/model/db.py Fri Oct 09 20:07:46 2020 +0200 @@ -46,7 +46,7 @@ import kallithea from kallithea.lib import ext_json, ssh from kallithea.lib.exceptions import DefaultUserException -from kallithea.lib.utils2 import (Optional, asbool, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, +from kallithea.lib.utils2 import (asbool, ascii_bytes, aslist, get_changeset_safe, get_clone_url, remove_prefix, safe_bytes, safe_int, safe_str, urlreadable) from kallithea.lib.vcs import get_backend from kallithea.lib.vcs.backends.base import EmptyChangeset @@ -243,10 +243,10 @@ return res @classmethod - def create_or_update(cls, key, val=Optional(''), type=Optional('unicode')): + def create_or_update(cls, key, val=None, type=None): """ Creates or updates Kallithea setting. If updates are triggered, it will only - update parameters that are explicitly set. Optional instance will be skipped. + update parameters that are explicitly set. 'None' values will be skipped. :param key: :param val: @@ -255,16 +255,16 @@ """ res = cls.get_by_name(key) if res is None: - val = Optional.extract(val) - type = Optional.extract(type) + # new setting + val = val if val is not None else '' + type = type if type is not None else 'unicode' res = cls(key, val, type) Session().add(res) else: - res.app_settings_name = key - if not isinstance(val, Optional): + if val is not None: # update if set res.app_settings_value = val - if not isinstance(type, Optional): + if type is not None: # update if set res.app_settings_type = type return res