vigiboard / vigiboard / config / app_cfg.py @ 5f2cd70a
History | View | Annotate | Download (6.25 KB)
1 |
# -*- coding: utf-8 -*-
|
---|---|
2 |
# vim: set fileencoding=utf-8 sw=4 ts=4 et :
|
3 |
"""
|
4 |
Global configuration file for TG2-specific settings in vigiboard.
|
5 |
|
6 |
This file complements development/deployment.ini.
|
7 |
|
8 |
Please note that **all the argument values are strings**. If you want to
|
9 |
convert them into boolean, for example, you should use the
|
10 |
:func:`paste.deploy.converters.asbool` function, as in::
|
11 |
|
12 |
from paste.deploy.converters import asbool
|
13 |
setting = asbool(global_conf.get('the_setting'))
|
14 |
|
15 |
"""
|
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
|
89 |
|
90 |
import vigiboard |
91 |
from vigiboard import model |
92 |
from vigiboard.lib import app_globals, helpers |
93 |
|
94 |
base_config = MyAppConfig('vigiboard')
|
95 |
base_config.renderers = [] |
96 |
|
97 |
# Pour gérer les thèmes, la notation "pointée" n'est pas utilisée.
|
98 |
# À la place, on indique le nom complet du template (ex: "index.html")
|
99 |
# lors de l'appel au décorateur @expose.
|
100 |
base_config.use_dotted_templatenames = False
|
101 |
|
102 |
# On définit la variable à False. En réalité, le comportement
|
103 |
# est le même que si elle valait toujours True, sauf que l'on
|
104 |
# met en place les middlewares nous même pour pouvoir gérer les
|
105 |
# thèmes (cf. ./middleware.py).
|
106 |
base_config.serve_static = False
|
107 |
|
108 |
base_config.package = vigiboard |
109 |
|
110 |
#Set the default renderer
|
111 |
base_config.default_renderer = 'genshi'
|
112 |
base_config.renderers.append('genshi')
|
113 |
# if you want raw speed and have installed chameleon.genshi
|
114 |
# you should try to use this renderer instead.
|
115 |
# warning: for the moment chameleon does not handle i18n translations
|
116 |
#base_config.renderers.append('chameleon_genshi')
|
117 |
|
118 |
#Configure the base SQLALchemy Setup
|
119 |
base_config.use_sqlalchemy = True
|
120 |
base_config.model = model |
121 |
base_config.DBSession = model.DBSession |
122 |
|
123 |
# Configure the authentication backend
|
124 |
base_config.auth_backend = 'sqlalchemy'
|
125 |
base_config.sa_auth.dbsession = model.DBSession |
126 |
# what is the class you want to use to search for users in the database
|
127 |
base_config.sa_auth.user_class = model.User |
128 |
# what is the class you want to use to search for groups in the database
|
129 |
base_config.sa_auth.group_class = model.UserGroup |
130 |
# what is the class you want to use to search for permissions in the database
|
131 |
base_config.sa_auth.permission_class = model.Permission |
132 |
# The name "groups" is already used for groups of hosts.
|
133 |
# We use "usergroups" when referering to users to avoid confusion.
|
134 |
base_config.sa_auth.translations.groups = 'usergroups'
|
135 |
|
136 |
# override this if you would like to provide a different who plugin for
|
137 |
# managing login and logout of your application
|
138 |
base_config.sa_auth.form_plugin = None
|
139 |
|
140 |
# You may optionally define a page where you want users to be redirected to
|
141 |
# on login:
|
142 |
base_config.sa_auth.post_login_url = '/post_login'
|
143 |
|
144 |
# You may optionally define a page where you want users to be redirected to
|
145 |
# on logout:
|
146 |
base_config.sa_auth.post_logout_url = '/post_logout'
|
147 |
|
148 |
|
149 |
##################################
|
150 |
# Settings specific to Vigiboard #
|
151 |
##################################
|
152 |
|
153 |
# Vigiboard version
|
154 |
base_config['vigiboard_version'] = u'0.1' |
155 |
|
156 |
# Links configuration
|
157 |
# XXX Should be part of ini settings.
|
158 |
base_config['vigiboard_links.eventdetails'] = {
|
159 |
'nagios': ['Nagios host details', 'http://example1.com/%(idaggregate)s'], |
160 |
'metrology': ['Metrology details', 'http://example2.com/%(idaggregate)s'], |
161 |
'security': ['Security details', 'http://example3.com/%(idaggregate)s'], |
162 |
'servicetype': ['Service Type', 'http://example4.com/%(idaggregate)s'], |
163 |
} |
164 |
|
165 |
# Plugins to use
|
166 |
# XXX Should be part of ini settings.
|
167 |
base_config['vigiboard_plugins'] = [
|
168 |
['shn', 'PluginSHN'], |
169 |
] |
170 |
|