X-Git-Url: https://git.openstreetmap.org./osqa.git/blobdiff_plain/9510ccb2cc2a0ad166436b9390314901f9be655a..9a977e5ab9fbc074e28aeb85c90a8707ffd66158:/forum/settings/base.py diff --git a/forum/settings/base.py b/forum/settings/base.py index 75687be..0e085e5 100644 --- a/forum/settings/base.py +++ b/forum/settings/base.py @@ -1,16 +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): @@ -29,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 @@ -38,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): @@ -54,22 +58,29 @@ class BaseSetting(object): v = kv.value self._temp = (v, datetime.now() + timedelta(seconds=TMP_MINICACHE_SECONDS)) return v + except KeyValue.DoesNotExist: + self._temp = (self.default, datetime.now() + timedelta(seconds=TMP_MINICACHE_SECONDS)) + self.save(self.default) except Exception, e: - return self.default + logging.error("Error retrieving setting from database (%s): %s" % (self.name, str(e))) + + return self.default def set_value(self, new_value): new_value = self._parse(new_value) + self._temp = None self.save(new_value) def save(self, value): - self._temp = None - from forum.models import KeyValue try: kv = KeyValue.objects.get(key=self.name) - except: + except KeyValue.DoesNotExist: kv = KeyValue(key=self.name) + except Exception, e: + logging.error("Error savin setting to database (%s): %s" % (self.name, str(e))) + return kv.value = value kv.save()