X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/21fb64ae6ee29e909e791156679604233b61c725..307956a2a0d3ce828d3684b72f5dc817e09e74cc:/forum/settings/base.py?ds=sidebyside diff --git a/forum/settings/base.py b/forum/settings/base.py index 08f3ea8..e160970 100644 --- a/forum/settings/base.py +++ b/forum/settings/base.py @@ -29,6 +29,9 @@ class BaseSetting(object): Setting.sets[set.name].append(self) + def __str__(self): + return str(self.value) + def __unicode__(self): return unicode(self.value) @@ -63,7 +66,12 @@ class BaseSetting(object): self.set_value(self.default) def _parse(self, value): - return value + if not isinstance(value, self.base_type): + try: + return self.base_type(value) + except: + pass + return value class Setting(object): @@ -76,7 +84,8 @@ class Setting(object): 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: