Revision 10848680
Utilsation des fonctionnalités fournies par vigilo-turbogears pour la config et la création des tables.
Quelques corrections mineures.
git-svn-id: https://vigilo-dev.si.c-s.fr/svn@950 b22e2e97-25c9-44ff-b637-2e5ceca36478
vigiboard/config/app_cfg.py | ||
---|---|---|
14 | 14 |
|
15 | 15 |
""" |
16 | 16 |
|
17 |
from tg.configuration import AppConfig |
|
18 |
|
|
19 |
class MyAppConfig(AppConfig): |
|
20 |
"""We overload AppConfig for our needs.""" |
|
21 |
|
|
22 |
def __init__(self, app_name): |
|
23 |
super(MyAppConfig, self).__init__() |
|
24 |
self.__app_name = app_name |
|
25 |
self.__tpl_translator = None |
|
26 |
|
|
27 |
def __setup_template_translator(self): |
|
28 |
from pkg_resources import resource_filename |
|
29 |
import gettext |
|
30 |
from tg.i18n import get_lang |
|
31 |
|
|
32 |
if self.__tpl_translator is None: |
|
33 |
i18n_dir = resource_filename('vigilo.themes', 'i18n') |
|
34 |
lang = get_lang() |
|
35 |
|
|
36 |
# During unit tests, no language is defined |
|
37 |
# which results in an error if gettext.translation |
|
38 |
# is used to retrieve translations. |
|
39 |
if lang is None: |
|
40 |
self.__tpl_translator = gettext.NullTranslations() |
|
41 |
else: |
|
42 |
self.__tpl_translator = gettext.translation( |
|
43 |
'theme', i18n_dir, get_lang()) |
|
44 |
|
|
45 |
def setup_paths(self): |
|
46 |
"""Add egg-aware search path to genshi.""" |
|
47 |
super(MyAppConfig, self).setup_paths() |
|
48 |
from pkg_resources import resource_filename |
|
49 |
|
|
50 |
app_templates = resource_filename( |
|
51 |
'vigilo.themes.templates', self.__app_name) |
|
52 |
common_templates = resource_filename( |
|
53 |
'vigilo.themes.templates', 'common') |
|
54 |
self.paths['templates'] = [app_templates, common_templates] |
|
55 |
|
|
56 |
def setup_genshi_renderer(self): |
|
57 |
"""Setup templates to use an alternate translator.""" |
|
58 |
# On reprend plusieurs éléments de "tg.configuration". |
|
59 |
from genshi.template import TemplateLoader |
|
60 |
from genshi.filters import Translator |
|
61 |
from tg.render import render_genshi |
|
62 |
from pkg_resources import resource_filename |
|
63 |
from tg.configuration import config |
|
64 |
|
|
65 |
def template_loaded(template): |
|
66 |
"""Called when a template is done loading.""" |
|
67 |
self.__setup_template_translator() |
|
68 |
template.filters.insert(0, Translator(self.__tpl_translator.ugettext)) |
|
69 |
|
|
70 |
def my_render_genshi(template_name, template_vars, **kwargs): |
|
71 |
self.__setup_template_translator() |
|
72 |
template_vars['l_'] = self.__tpl_translator.ugettext |
|
73 |
return render_genshi(template_name, template_vars, **kwargs) |
|
74 |
|
|
75 |
loader = TemplateLoader(search_path=self.paths.templates, |
|
76 |
auto_reload=self.auto_reload_templates, |
|
77 |
callback=template_loaded) |
|
78 |
|
|
79 |
config['pylons.app_globals'].genshi_loader = loader |
|
80 |
self.render_functions.genshi = my_render_genshi |
|
81 |
|
|
82 |
def setup_sqlalchemy(self): |
|
83 |
""" |
|
84 |
TG2 needs to configure the DB session before anything else, then it |
|
85 |
calls init_model(). In our case, the DB session is already configured |
|
86 |
so the function call is unnecessary. We suppress TG2's behaviour here. |
|
87 |
""" |
|
88 |
pass |
|
17 |
from vigilo.turbogears import VigiloAppConfig |
|
89 | 18 |
|
90 | 19 |
import vigiboard |
91 | 20 |
from vigiboard import model |
92 | 21 |
from vigiboard.lib import app_globals, helpers |
93 | 22 |
|
94 |
base_config = MyAppConfig('vigiboard')
|
|
23 |
base_config = VigiloAppConfig('vigiboard')
|
|
95 | 24 |
base_config.renderers = [] |
96 | 25 |
|
97 | 26 |
# Pour gérer les thèmes, la notation "pointée" n'est pas utilisée. |
Also available in: Unified diff