X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/c60905fb1eb3937efb37113858e0dff73a40460b..a55b5f91ad440cd0c35ac45cbe2515e238e9a7c8:/forum/settings/base.py diff --git a/forum/settings/base.py b/forum/settings/base.py index cdc80b0..cc706bc 100644 --- a/forum/settings/base.py +++ b/forum/settings/base.py @@ -1,17 +1,18 @@ import django.dispatch -from django.utils.encoding import force_unicode +from django.utils.encoding import force_unicode, smart_unicode from datetime import datetime, timedelta import logging TMP_MINICACHE_SECONDS = 5 class SettingSet(list): - def __init__(self, name, title, description, weight=1000, markdown=False): + def __init__(self, name, title, description, weight=1000, markdown=False, can_preview=False): self.name = name self.title = title self.description = description self.weight = weight self.markdown = markdown + self.can_preview = can_preview class BaseSetting(object): @@ -30,6 +31,8 @@ class BaseSetting(object): self._temp = None if set is not None: + self.set = set + if not set.name in Setting.sets: Setting.sets[set.name] = set @@ -39,7 +42,7 @@ class BaseSetting(object): return str(self.value) def __unicode__(self): - return unicode(self.value) + return smart_unicode(self.value) @property def value(self): @@ -57,6 +60,7 @@ class BaseSetting(object): return v except KeyValue.DoesNotExist: self._temp = (self.default, datetime.now() + timedelta(seconds=TMP_MINICACHE_SECONDS)) + self.save(self.default) except Exception, e: logging.error("Error retrieving setting from database (%s): %s" % (self.name, str(e))) @@ -75,7 +79,7 @@ class BaseSetting(object): except KeyValue.DoesNotExist: kv = KeyValue(key=self.name) except Exception, e: - logging.error("Error savin setting to database (%s): %s" % (self.name, str(e))) + logging.error("Error saving setting to database (%s): %s" % (self.name, str(e))) return kv.value = value @@ -120,5 +124,3 @@ class Setting(object): Setting.emulators[deftype] = emul return emul(name, default, set, field_context) - -