Project

General

Profile

Revision 98c1bcf7

ID98c1bcf719d5c917c27471a4a14d497aa2a16430
Parent 316281de
Child d2be9163

Added by Thomas BURGUIERE almost 15 years ago

tburguie: 1ere version fonctionnelle (ou qui ne plante pas...)

git-svn-id: https://vigilo-dev.si.c-s.fr/svn@922 b22e2e97-25c9-44ff-b637-2e5ceca36478

View differences:

vigigraph/config/app_cfg.py
1 1
# -*- coding: utf-8 -*-
2
# vim: set fileencoding=utf-8 sw=4 ts=4 et :
2 3
"""
3 4
Global configuration file for TG2-specific settings in vigigraph.
4 5

  
......
15 16

  
16 17
from tg.configuration import AppConfig
17 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

  
18 90
import vigigraph
19 91
from vigigraph import model
20
from vigigraph.lib import app_globals, helpers 
92
from vigigraph.lib import app_globals, helpers
21 93

  
22
base_config = AppConfig()
94
base_config = MyAppConfig('vigigraph')
23 95
base_config.renderers = []
24 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

  
25 108
base_config.package = vigigraph
26 109

  
27 110
#Set the default renderer
......
34 117

  
35 118
#Configure the base SQLALchemy Setup
36 119
base_config.use_sqlalchemy = True
37
base_config.model = vigigraph.model
38
base_config.DBSession = vigigraph.model.DBSession
120
base_config.model = model
121
base_config.DBSession = model.DBSession
39 122

  
40 123
# Configure the authentication backend
41 124
base_config.auth_backend = 'sqlalchemy'
......
43 126
# what is the class you want to use to search for users in the database
44 127
base_config.sa_auth.user_class = model.User
45 128
# what is the class you want to use to search for groups in the database
46
base_config.sa_auth.group_class = model.Group
129
base_config.sa_auth.group_class = model.UserGroup
47 130
# what is the class you want to use to search for permissions in the database
48 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'
49 135

  
50 136
# override this if you would like to provide a different who plugin for
51 137
# managing login and logout of your application
......
58 144
# You may optionally define a page where you want users to be redirected to
59 145
# on logout:
60 146
base_config.sa_auth.post_logout_url = '/post_logout'
147

  
148

  
149
##################################
150
# Settings specific to Vigigraph #
151
##################################
152

  
153
# Vigigraph version
154
base_config['vigigraph_version'] = u'0.1'
155

  

Also available in: Unified diff