X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/87e592dc4c9e0321635350da8c9f1624554a604f..f32577466e18584c0adb9e9845a0f50faa5db777:/forum/settings/base.py?ds=sidebyside diff --git a/forum/settings/base.py b/forum/settings/base.py index 5bcf5fc..398ed11 100644 --- a/forum/settings/base.py +++ b/forum/settings/base.py @@ -66,6 +66,15 @@ class BaseSetting(object): self.set_value(self.default) def _parse(self, value): + if not isinstance(value, self.base_type): + try: + return self.base_type(value) + except: + pass + return value + +class AnyTypeSetting(BaseSetting): + def _parse(self, value): return value @@ -74,12 +83,16 @@ class Setting(object): sets = {} def __new__(cls, name, default, set=None, field_context=None): + if default is None: + return AnyTypeSetting(name, default, set, field_context) + deftype = type(default) if deftype in Setting.emulators: emul = Setting.emulators[deftype] else: - emul = type(deftype.__name__ + cls.__name__, (BaseSetting,), {}) + emul = type(deftype.__name__ + cls.__name__, (BaseSetting,), {'base_type': deftype}) + fns = [n for n, f in [(p, getattr(deftype, p)) for p in dir(deftype) if not p in dir(cls)] if callable(f)] for n in fns: