Exemplo n.º 1
0
def block_raw(request, block_id):
    """
    Renders the view associated with the block with the given ID.

    The view will be rendered verbatim, and thus will *not*
    constitute well-formed HTML.  Use this to include the block in
    existing pages not able to embed the view itself, for example
    using AJAX.

    :param request: the HTTP request that retrieved this view
    :param block_id: the identifier of the block (usually its name)
    :type block_id: string, integer or `GridBlock`
    :rtype: the result of calling the block's view with this request
    """

    block = GridBlock.get_or_404(block_id)

    return render(
        request,
        'grid/block_indirect.html',
        {
            'box': block,
            'template': template_of(block),
        }
    )
Exemplo n.º 2
0
def grid_block(context, block_id):
    """
    Renders the grid block of the given ID.

    :param block_id: the ID (name or primary key) of the block
    :type block_id: string, integer or `GridBlock`
    :rtype: a template tag node

    """
    # Effectively pass the entire existing context with the
    # difference that 'box' is set to the block ID and 'template' to
    # the actual template block_indirect should render.
    # This is required for embedded views to work properly, just
    # returning a context of {'box': GridBlock.get(block_id)} causes
    # embedded views to break.
    box = GridBlock.get(block_id)
    context['box'] = box
    context['template'] = views.template_of(box)
    return context