Beispiel #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')

        class MockExt(object):
            identifier = 'foobar'

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

        add_jinja2_extension(self.config, MockExt)

        u = _get_or_build_default_environment(self.config.registry)
        self.assertTrue('foobar' in u.extensions)
Beispiel #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')

        class MockExt(object):
            identifier = 'foobar'

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

        add_jinja2_extension(self.config, MockExt)

        u = _get_or_build_default_environment(self.config.registry)
        self.assertTrue('foobar' in u.extensions)
Beispiel #3
0
def main(global_config, **settings):
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    session_factory = session_factory_from_settings(settings)
    authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(settings=settings,
                          root_factory=RootFactory,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy,
                          session_factory=session_factory)

    config.include('pyramid_jinja2')
    add_jinja2_extension(config, ext.do)
    add_jinja2_extension(config, ext.loopcontrols)
    add_jinja2_extension(config, SelectiveHTMLCompress)
    add_jinja2_search_path(config, 'alchemist:general/layout/')
    add_jinja2_search_path(config, 'alchemist:general/blocks/')
    add_jinja2_search_path(config, 'alchemist:general/helpers/')

    config.include('pyramid_mailer')

    scheduler.add_jobstore('sqlalchemy', url=settings['sqlalchemy.url'])
    scheduler_tz = settings.get('scheduler.timezone')
    if scheduler_tz:
        scheduler.configure(timezone=scheduler_tz)
    scheduler.pyramid_registry = config.registry

    def get_user(request):
        id = authenticated_userid(request)
        if not id:
            return None
        return User.bid(id)

    config.add_request_method(get_user, 'user', reify=True)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('export-dumps', 'export-dumps', cache_max_age=3600)
    config.add_static_view('img', 'static/img', cache_max_age=3600)
    config.add_static_view('css', 'static/css', cache_max_age=3600)
    config.add_static_view('js', 'static/js', cache_max_age=3600)
    config.add_static_view('fonts', 'static/fonts', cache_max_age=3600)
    config.add_static_view('upload', 'upload', cache_max_age=3600)

    config.scan('alchemist')
    # it's important that this is after scan
    # TODO: make a venusian? decorator, maybe will not need the include then
    config.include('alchemist:qaforum.emails')
    scheduler.start()

    return config.make_wsgi_app()
Beispiel #4
0
def main(global_config, **settings):
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    session_factory = session_factory_from_settings(settings)
    authn_policy = SessionAuthenticationPolicy(callback=groupfinder)
    authz_policy = ACLAuthorizationPolicy()

    config = Configurator(settings=settings,
                          root_factory=RootFactory,
                          authentication_policy=authn_policy,
                          authorization_policy=authz_policy,
                          session_factory=session_factory)

    config.include('pyramid_jinja2')
    add_jinja2_extension(config, ext.do)
    add_jinja2_extension(config, ext.loopcontrols)
    add_jinja2_extension(config, SelectiveHTMLCompress)
    add_jinja2_search_path(config, 'alchemist:templates')
    add_jinja2_search_path(config, 'alchemist:templates/layout')
    add_jinja2_search_path(config, 'alchemist:templates/helpers')
    add_jinja2_search_path(config, 'alchemist:templates/auth')
    add_jinja2_search_path(config, 'alchemist:templates/company')
    add_jinja2_search_path(config, 'alchemist:templates/blocks')
    add_jinja2_search_path(config, 'alchemist:templates/helpers')

    config.include('pyramid_dogpile_cache')
    cache = get_region('main')

    config.include('pyramid_mailer')

    def add_path(config, view, path, **kwargs):
        route_name = '%s_%s' % (qualname(view), path.replace('/', '_').split('{')[0])
        config.add_route(route_name, path)
        config.add_view(view, route_name=route_name, **kwargs)

    config.add_directive('add_path', add_path)

    def get_user(request):
        id = authenticated_userid(request)
        if not id:
            return None
        return User.bid(id)

    config.add_request_method(get_user, 'user', reify=True)

    config.add_static_view('static', 'static', cache_max_age=3600)
    config.add_static_view('export-dumps', 'export-dumps', cache_max_age=3600)
    config.add_static_view('img', 'static/img', cache_max_age=3600)
    config.add_static_view('css', 'static/css', cache_max_age=3600)
    config.add_static_view('js', 'static/js', cache_max_age=3600)
    config.add_static_view('fonts', 'static/fonts', cache_max_age=3600)
    config.add_static_view('upload', 'upload', cache_max_age=3600)

    from alchemist import routes_admin
    from alchemist import routes_other
    from alchemist import routes_auth
    from alchemist import routes_user
    config.include(routes_admin.includeme)
    config.include(routes_other.includeme)
    config.include(routes_auth.includeme)
    config.include(routes_user.includeme)
    config.scan('alchemist.views.system')

    return config.make_wsgi_app()