1 # -*- coding: utf-8 -*-
2 # This file is part of PrawoKultury, licensed under GNU Affero GPLv3 or later.
3 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
5 from django.conf import settings
6 from textile import Textile
9 class TextilePL(Textile):
10 glyph_defaults = [(name, repl)
11 for (name, repl) in Textile.glyph_defaults
12 if name != 'txt_quote_double_open']
13 glyph_defaults.append(('txt_quote_double_open', '„'))
17 return TextilePL().textile(text)
20 def textile_restricted_pl(text):
21 return TextilePL(restricted=True, lite=True,
22 noimage=True, auto_link=True).textile(
26 class LazyUGettextLazy():
27 """You can use it to internationalize strings in settings.
29 Just import this class as gettext.
34 def __init__(self, text):
37 def __unicode__(self):
39 from django.utils.translation import ugettext_lazy
40 LazyUGettextLazy._ = staticmethod(ugettext_lazy)
41 LazyUGettextLazy.real = True
42 return unicode(self._(self.text))
45 class AppSettings(object):
46 """Allows specyfying custom settings for an app, with default values.
48 Just subclass, set some properties and instantiate with a prefix.
49 Getting a SETTING from an instance will check for prefix_SETTING
50 in project settings if set, else take the default. The value will be
51 then filtered through _more_SETTING method, if there is one.
54 def __init__(self, prefix):
57 def __getattribute__(self, name):
58 if name.startswith('_'):
59 return object.__getattribute__(self, name)
60 value = getattr(settings,
61 "%s_%s" % (self._prefix, name),
62 object.__getattribute__(self, name))
63 more = "_more_%s" % name
64 if hasattr(self, more):
65 value = getattr(self, more)(value)