Пример #1
0
def includeme(config):
    """ Initialize views and renderers at app start-up time. """

    settings = config.get_settings()

    config.add_renderer('json', json_renderer_factory)
    config.include('.traversal')

    default_discussion = settings.get('default_discussion', None)
    if default_discussion:
        config.add_route('discussion_list', '/discussions')
        config.add_view(lambda req: HTTPFound('/' + default_discussion),
                        route_name='default_disc_redirect')

        config.add_route('default_disc_redirect', '/')
    else:
        config.add_route('discussion_list', '/')

    config.include(backbone_include, route_prefix='/debate/{discussion_slug}')
    config.include(legacy_backbone_include, route_prefix='/{discussion_slug}')

    if asbool(config.get_settings().get('assembl_handle_exceptions', 'true')):
        config.add_view(error_view,
                        context=Exception,
                        renderer='assembl:templates/error_page.jinja2')

    # View for error template in development environment only
    if os.getenv('NODE_ENV') == "development":
        config.add_route('error_template', '/error_template')
        config.add_view(error_template,
                        route_name='error_template',
                        renderer='assembl:templates/error_page.jinja2')

    #  authentication
    config.include('.auth')

    config.include('.api')
    config.include('.api2')
    config.include('.admin')
    config.include('.search')

    config.add_route('home-auto', '/debate/{discussion_slug}/')
    config.add_route('home', '/debate/{discussion_slug}')

    def redirector(request):
        return HTTPMovedPermanently(
            request.route_url(
                'home',
                discussion_slug=request.matchdict.get('discussion_slug')))

    config.add_view(redirector, route_name='home-auto')
    default_context['cache_bust'] = \
        config.registry.settings['requirejs.cache_bust']

    # Scan now, to get cornice views
    config.scan('.')
    config.include('.discussion')  # Must be last routes to be called
Пример #2
0
def includeme(config):
    """ Initialize views and renderers at app start-up time. """

    settings = config.get_settings()

    config.add_renderer('json', json_renderer_factory)
    config.include('.traversal')

    default_discussion = settings.get('default_discussion', None)
    if default_discussion:
        config.add_route('discussion_list', '/discussions')
        config.add_view(
            lambda req: HTTPFound('/' + default_discussion),
            route_name='default_disc_redirect')

        config.add_route('default_disc_redirect', '/')
    else:
        config.add_route('discussion_list', '/')

    config.include(backbone_include, route_prefix='/debate/{discussion_slug}')
    config.include(legacy_backbone_include, route_prefix='/{discussion_slug}')

    if asbool(config.get_settings().get('assembl_handle_exceptions', 'true')):
        config.add_view(error_view, context=Exception,
                        renderer='assembl:templates/error_page.jinja2')

    # View for error template in development environment only
    if os.getenv('NODE_ENV') == "development":
        config.add_route('error_template', '/error_template')
        config.add_view(error_template, route_name='error_template',
                        renderer='assembl:templates/error_page.jinja2')

    #  authentication
    config.include('.auth')

    config.include('.api')
    config.include('.api2')
    config.include('.admin')
    config.include('.search')

    config.add_route('home-auto', '/debate/{discussion_slug}/')
    config.add_route('home', '/debate/{discussion_slug}')

    def redirector(request):
        return HTTPMovedPermanently(request.route_url('home', discussion_slug=request.matchdict.get('discussion_slug')))
    config.add_view(redirector, route_name='home-auto')
    default_context['cache_bust'] = \
        config.registry.settings['requirejs.cache_bust']

    # Scan now, to get cornice views
    config.scan('.')
    config.include('.discussion')  # Must be last routes to be called