X-Git-Url: https://git.mdrn.pl/prawokultury.git/blobdiff_plain/44090c986d9a16f6913047c25319c446bb9308ad..fa8909f95f314f1bea5f52b81381304c68a75417:/prawokultury/helpers.py?ds=sidebyside diff --git a/prawokultury/helpers.py b/prawokultury/helpers.py index aa8e3dd..5877e0b 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,7 +23,6 @@ def textile_restricted_pl(text): text, rel='nofollow') - class LazyUGettextLazy(): """You can use it to internationalize strings in settings. @@ -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