dirty, ugly but workable
[prawokultury.git] / prawokultury / helpers.py
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.
4 #
5 from textile import Textile
6
7
8 class TextilePL(Textile):
9     glyph_defaults = [(name, repl) 
10         for (name, repl) in Textile.glyph_defaults
11         if name != 'txt_quote_double_open']
12     glyph_defaults.append(('txt_quote_double_open', '„'))
13
14
15 def textile_pl(text):
16     return TextilePL().textile(text)
17
18
19 def textile_restricted_pl(text):
20     return TextilePL(restricted=True, lite=True,
21                    noimage=True, auto_link=False).textile(
22                         text, rel='nofollow')
23
24
25
26 class LazyUGettextLazy():
27     """You can use it to internationalize strings in settings.
28
29     Just import this class as gettext.
30     """
31     _ = lambda s: s
32     real = False
33
34     def __init__(self, text):
35         self.text = text
36
37     def __unicode__(self):
38         if not self.real:
39             from django.utils.translation import ugettext_lazy
40             LazyUGettextLazy._ = staticmethod(ugettext_lazy)
41             LazyUGettextLazy.real = True
42         return unicode(self._(self.text))