Example #1
0
    def _getDebugInfo(self, request, start_response):
        app = get_app_for_server(self.appfactory)
        if not app.config.get('site/enable_debug_info', True):
            raise Forbidden("PieCrust debug info isn't enabled.")

        found = False
        page_path = request.args.get('page')
        try:
            req_page = get_requested_page(app, page_path)
            found = (req_page is not None)
        except (RouteNotFoundError, PageNotFoundError):
            pass
        if not found:
            raise NotFound("No such page: %s" % page_path)

        ctx = DataBuildingContext(req_page.page,
                                  sub_num=req_page.sub_num)
        data = build_page_data(ctx)

        var_path = request.args.getlist('var')
        if not var_path:
            var_path = None
        output = build_var_debug_info(data, var_path)

        response = Response(output, mimetype='text/html')
        return response(request.environ, start_response)
Example #2
0
    def _getDebugInfo(self, request, start_response):
        app = get_app_for_server(self.root_dir, debug=self.debug,
                                 sub_cache_dir=self.sub_cache_dir)
        if not app.config.get('site/enable_debug_info'):
            return Forbidden()

        found = False
        page_path = request.args.get('page')
        try:
            req_page = get_requested_page(app, page_path)
            found = (req_page is not None)
        except (RouteNotFoundError, PageNotFoundError):
            pass
        if not found:
            return NotFound("No such page: %s" % page_path)

        ctx = DataBuildingContext(req_page.qualified_page,
                                  page_num=req_page.page_num)
        data = build_page_data(ctx)

        var_path = request.args.getlist('var')
        if not var_path:
            var_path = None
        output = build_var_debug_info(data, var_path)

        response = Response(output, mimetype='text/html')
        return response(request.environ, start_response)
Example #3
0
def _build_render_data(ctx):
    data_ctx = DataBuildingContext(ctx.page, ctx.sub_num)
    data_ctx.pagination_source = ctx.pagination_source
    data_ctx.pagination_filter = ctx.pagination_filter
    page_data = build_page_data(data_ctx)
    if ctx.custom_data:
        page_data._appendMapping(ctx.custom_data)
    return page_data
Example #4
0
def _build_render_data(ctx):
    data_ctx = DataBuildingContext(ctx.page, ctx.sub_num)
    data_ctx.pagination_source = ctx.pagination_source
    data_ctx.pagination_filter = ctx.pagination_filter
    page_data = build_page_data(data_ctx)
    if ctx.custom_data:
        page_data._appendMapping(ctx.custom_data)
    return page_data
Example #5
0
def _build_render_data(ctx):
    with ctx.app.env.timerScope("PageDataBuild"):
        data_ctx = DataBuildingContext(ctx.page, page_num=ctx.page_num)
        data_ctx.pagination_source = ctx.pagination_source
        data_ctx.pagination_filter = ctx.pagination_filter
        page_data = build_page_data(data_ctx)
        if ctx.custom_data:
            page_data._appendMapping(ctx.custom_data)
        return page_data
Example #6
0
def _build_render_data(ctx):
    with ctx.app.env.timerScope("PageDataBuild"):
        data_ctx = DataBuildingContext(ctx.page, page_num=ctx.page_num)
        data_ctx.pagination_source = ctx.pagination_source
        data_ctx.pagination_filter = ctx.pagination_filter
        page_data = build_page_data(data_ctx)
        if ctx.custom_data:
            page_data._appendMapping(ctx.custom_data)
        return page_data
Example #7
0
def _do_render_page_segments_from_ctx(ctx):
    eis = ctx.app.env.exec_info_stack
    eis.pushPage(ctx.page, ctx)
    ctx.setCurrentPass(PASS_FORMATTING)
    try:
        data_ctx = DataBuildingContext(ctx.page, page_num=ctx.page_num)
        page_data = build_page_data(data_ctx)
        return _do_render_page_segments(ctx.page, page_data)
    finally:
        ctx.setCurrentPass(PASS_NONE)
        eis.popPage()
Example #8
0
def _do_render_page_segments_from_ctx(ctx):
    eis = ctx.app.env.exec_info_stack
    eis.pushPage(ctx.page, ctx)
    ctx.setCurrentPass(PASS_FORMATTING)
    try:
        data_ctx = DataBuildingContext(ctx.page, page_num=ctx.page_num)
        page_data = build_page_data(data_ctx)
        return _do_render_page_segments(ctx.page, page_data)
    finally:
        ctx.setCurrentPass(PASS_NONE)
        eis.popPage()
Example #9
0
def render_page(ctx):
    eis = ctx.app.env.exec_info_stack
    eis.pushPage(ctx.page, ctx)
    try:
        page = ctx.page

        # Build the data for both segment and layout rendering.
        data_ctx = DataBuildingContext(page, page_num=ctx.page_num)
        data_ctx.pagination_source = ctx.pagination_source
        data_ctx.pagination_filter = ctx.pagination_filter
        page_data = build_page_data(data_ctx)
        if ctx.custom_data:
            page_data.update(ctx.custom_data)

        # Render content segments.
        ctx.setCurrentPass(PASS_FORMATTING)
        repo = ctx.app.env.rendered_segments_repository
        if repo and not ctx.force_render:
            cache_key = ctx.uri
            page_time = page.path_mtime
            contents = repo.get(
                    cache_key,
                    lambda: _do_render_page_segments(page, page_data),
                    fs_cache_time=page_time)
        else:
            contents = _do_render_page_segments(page, page_data)

        # Render layout.
        ctx.setCurrentPass(PASS_RENDERING)
        layout_name = page.config.get('layout')
        if layout_name is None:
            layout_name = page.source.config.get('default_layout', 'default')
        null_names = ['', 'none', 'nil']
        if layout_name not in null_names:
            build_layout_data(page, page_data, contents)
            output = render_layout(layout_name, page, page_data)
        else:
            output = contents['content']

        rp = RenderedPage(page, ctx.uri, ctx.page_num)
        rp.data = page_data
        rp.content = output
        return rp
    finally:
        ctx.setCurrentPass(PASS_NONE)
        eis.popPage()
Example #10
0
def render_page(ctx):
    eis = ctx.app.env.exec_info_stack
    eis.pushPage(ctx.page, ctx)
    try:
        page = ctx.page

        # Build the data for both segment and layout rendering.
        data_ctx = DataBuildingContext(page, page_num=ctx.page_num)
        data_ctx.pagination_source = ctx.pagination_source
        data_ctx.pagination_filter = ctx.pagination_filter
        page_data = build_page_data(data_ctx)
        if ctx.custom_data:
            page_data.update(ctx.custom_data)

        # Render content segments.
        ctx.setCurrentPass(PASS_FORMATTING)
        repo = ctx.app.env.rendered_segments_repository
        if repo and not ctx.force_render:
            cache_key = ctx.uri
            page_time = page.path_mtime
            contents = repo.get(
                cache_key,
                lambda: _do_render_page_segments(page, page_data),
                fs_cache_time=page_time)
        else:
            contents = _do_render_page_segments(page, page_data)

        # Render layout.
        ctx.setCurrentPass(PASS_RENDERING)
        layout_name = page.config.get('layout')
        if layout_name is None:
            layout_name = page.source.config.get('default_layout', 'default')
        null_names = ['', 'none', 'nil']
        if layout_name not in null_names:
            build_layout_data(page, page_data, contents)
            output = render_layout(layout_name, page, page_data)
        else:
            output = contents['content']

        rp = RenderedPage(page, ctx.uri, ctx.page_num)
        rp.data = page_data
        rp.content = output
        return rp
    finally:
        ctx.setCurrentPass(PASS_NONE)
        eis.popPage()