]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/settings/base.py
changed "reputation" to "karma"
[osqa.git] / forum / settings / base.py
index 08f3ea8b60ca66504b9eb7477c30f3818356d717..398ed11907d7b33c214d168eb5036ffa2900ef40 100644 (file)
@@ -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,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
 
 
@@ -71,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: