X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/44090c986d9a16f6913047c25319c446bb9308ad..5af5cc14f6b2ecddcad714053e048e39d52ca02d:/prawokultury/helpers.py diff --git a/prawokultury/helpers.py b/prawokultury/helpers.py index aa8e3dd..23520ec 100644 --- a/prawokultury/helpers.py +++ b/prawokultury/helpers.py @@ -2,6 +2,7 @@ # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from django.conf import settings from textile import Textile @@ -22,8 +23,7 @@ def textile_restricted_pl(text): text, rel='nofollow') - -class LazyUGettextLazy(): +class LazyUGettextLazy(object): """You can use it to internationalize strings in settings. Just import this class as gettext. @@ -40,3 +40,27 @@ class LazyUGettextLazy(): LazyUGettextLazy._ = staticmethod(ugettext_lazy) LazyUGettextLazy.real = True return unicode(self._(self.text)) + + +class AppSettings(object): + """Allows specyfying custom settings for an app, with default values. + + Just subclass, set some properties and instantiate with a prefix. + Getting a SETTING from an instance will check for prefix_SETTING + in project settings if set, else take the default. The value will be + then filtered through _more_SETTING method, if there is one. + + """ + def __init__(self, prefix): + self._prefix = prefix + + def __getattribute__(self, name): + if name.startswith('_'): + return object.__getattribute__(self, name) + value = getattr(settings, + "%s_%s" % (self._prefix, name), + object.__getattribute__(self, name)) + more = "_more_%s" % name + if hasattr(self, more): + value = getattr(self, more)(value) + return value