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 django.http import HttpResponse, HttpResponseRedirect
7 from textile import Textile
10 class TextilePL(Textile):
11 glyph_defaults = [(name, repl)
12 for (name, repl) in Textile.glyph_defaults
13 if name != 'txt_quote_double_open']
14 glyph_defaults.append(('txt_quote_double_open', '„'))
18 return TextilePL().textile(text)
21 def textile_restricted_pl(text):
22 return TextilePL(restricted=True, lite=True,
23 noimage=True, auto_link=False).textile(
27 class LazyUGettextLazy(object):
28 """You can use it to internationalize strings in settings.
30 Just import this class as gettext.
35 def __init__(self, text):
38 def __unicode__(self):
40 from django.utils.translation import ugettext_lazy
41 LazyUGettextLazy._ = staticmethod(ugettext_lazy)
42 LazyUGettextLazy.real = True
43 return unicode(self._(self.text))
46 class AppSettings(object):
47 """Allows specyfying custom settings for an app, with default values.
49 Just subclass, set some properties and instantiate with a prefix.
50 Getting a SETTING from an instance will check for prefix_SETTING
51 in project settings if set, else take the default. The value will be
52 then filtered through _more_SETTING method, if there is one.
55 def __init__(self, prefix):
58 def __getattribute__(self, name):
59 if name.startswith('_'):
60 return object.__getattribute__(self, name)
61 value = getattr(settings,
62 "%s_%s" % (self._prefix, name),
63 object.__getattribute__(self, name))
64 more = "_more_%s" % name
65 if hasattr(self, more):
66 value = getattr(self, more)(value)
71 if settings.X_ACCEL_REDIRECT:
72 response = HttpResponse()
73 response['Content-Type'] = ""
74 response['X-Accel-Redirect'] = url
77 return HttpResponseRedirect(url)