Python 3, Django 1.7+ compatilibity, some tests.
[fnpdjango.git] / fnpdjango / utils / settings.py
1 """
2 Utilities for global settings.
3 """
4 from django.utils.encoding import python_2_unicode_compatible
5
6 # Use Python3 str.
7 try:
8     unicode
9 except NameError:
10     pass
11 else:
12     str = unicode
13
14
15 @python_2_unicode_compatible
16 class LazyUGettextLazy(object):
17     """You can use it to internationalize strings in settings.
18
19     Just import this class as gettext.
20     """
21     _ = lambda s: s
22     real = False
23
24     def __init__(self, text):
25         self.text = text
26
27     def __str__(self):
28         if not self.real:
29             from django.utils.translation import ugettext_lazy
30             LazyUGettextLazy._ = staticmethod(ugettext_lazy)
31             LazyUGettextLazy.real = True
32         return str(self._(self.text))
33
34