Exemple #1
0
    def test_add_jinja2_extension(self):
        from pyramid_jinja2 import (add_jinja2_extension,
                                    _get_or_build_default_environment)
        self.config.include('pyramid_jinja2')
        env_before = _get_or_build_default_environment(self.config.registry)

        class MockExt(object):
            identifier = 'foobar'

            def __init__(self, x):
                self.x = x

        add_jinja2_extension(self.config, MockExt)

        env_after = _get_or_build_default_environment(self.config.registry)
        self.assertTrue('foobar' in env_after.extensions)
        self.assertTrue(env_before is env_after)
Exemple #2
0
    def test_add_jinja2_extension(self):
        from pyramid_jinja2 import (add_jinja2_extension,
                                    _get_or_build_default_environment)
        self.config.include('pyramid_jinja2')
        env_before = _get_or_build_default_environment(self.config.registry)

        class MockExt(object):
            identifier = 'foobar'

            def __init__(self, x):
                self.x = x

        add_jinja2_extension(self.config, MockExt)

        env_after = _get_or_build_default_environment(self.config.registry)
        self.assertTrue('foobar' in env_after.extensions)
        self.assertTrue(env_before is env_after)
Exemple #3
0
    def test_it(self):
        from pyramid_jinja2 import _get_or_build_default_environment
        u = _get_or_build_default_environment(self.config.registry)
        self.assertTrue(hasattr(u, 'install_gettext_translations'))

        self.config.add_translation_dirs('pyramid_jinja2.tests:locale/')
        self.request.locale_name = 'en'
        template = u.get_template('pyramid_jinja2.tests:templates/i18n.jinja2')
        self.assertEqual(template.render(),
                         u'some untranslated text here\nyay it worked!')
Exemple #4
0
    def test_it(self):
        from pyramid_jinja2 import _get_or_build_default_environment
        u = _get_or_build_default_environment(self.config.registry)
        self.assertTrue(hasattr(u, 'install_gettext_translations'))

        self.config.add_translation_dirs('pyramid_jinja2.tests:locale/')
        self.request.locale_name = 'en'
        template = u.get_template('pyramid_jinja2.tests:templates/i18n.jinja2')
        self.assertEqual(template.render(),
                         u'some untranslated text here\nyay it worked!')
Exemple #5
0
def main(global_config, **settings):
    """ This function returns a Pyramid WSGI application.
    """

    session_factory = session_factory_from_settings(settings)

    authn_policy = AuthTktAuthenticationPolicy(secret="s0secret")
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(
        settings=settings,
        #        root_factory='chatapp.security.RootFactory',
        authentication_policy=authn_policy,
        authorization_policy=authz_policy,
        session_factory=session_factory,
    )
    jinja_env = _get_or_build_default_environment(config.registry)

    config.add_route("home", "/")
    config.add_sockjs_route("chat-service", session=EchoSession)
    config.add_route("broadcast", "/broadcast")

    config.scan()
    return config.make_wsgi_app()
Exemple #6
0
def renderer_factory(info):
    environment = _get_or_build_default_environment(info.registry)
    return Jinja2AutoTemplateRenderer(info, environment)
Exemple #7
0
def renderer_factory(info):
    environment = _get_or_build_default_environment(info.registry)
    return Jinja2AutoTemplateRenderer(info, environment)