@contextfunction
def link_block(context, object):

    request = context['request']

    response_format = 'html'
    if 'response_format' in context:
        response_format = context['response_format']

    response_format_tags = response_format
    if 'response_format_tags' in context:
        response_format_tags = context['response_format_tags']

    if request.GET and 'link_add' in request.GET:
        if request.POST:

            if 'cancel' in request.POST:
                links = Object.filter_by_request(
                    context['request'], object.links)
                return Markup(render_to_string('core/tags/link_block',
                                               {'object': object, 'links': links,
                                                   'request': request, 'path': request.path},
                                               context_instance=RequestContext(
                                                   request),
                                               response_format=response_format))

            form = ObjectLinksForm(
                request.user.profile, response_format_tags, object, request.POST)

            if form.is_valid() and request.user.profile.has_permission(object, mode='w'):
                object.links.add(form.cleaned_data['links'])
                links = Object.filter_by_request(
                    context['request'], object.links)
                return Markup(render_to_string('core/tags/link_block',
                                               {'object': object, 'links': links,
                                                   'request': request, 'path': request.path},
                                               context_instance=RequestContext(
                                                   request),
                                               response_format=response_format))

        links = Object.filter_by_request(context['request'], object.links)
        form = ObjectLinksForm(
            request.user.profile, response_format_tags, instance=object)

        context = {'object': object, 'path': request.path,
                   'form': form, 'links': links}

        if 'ajax' in response_format_tags:
            context = converter.preprocess_context(context)

        rendered_string = render_to_string('core/tags/link_block_edit', context,
                                           context_instance=RequestContext(
                                               request),
                                           response_format=response_format)

        return Markup(rendered_string)

    elif request.GET and 'link_delete' in request.GET:

        if request.user.profile.has_permission(object, mode='w'):
            try:
                link = Object.objects.get(pk=request.GET['link_delete'])
                object.links.remove(link)
            except Exception:
                pass

    links = Object.filter_by_request(context['request'], object.links)

    return Markup(render_to_string('core/tags/link_block',
                                   {'object': object, 'links': links, 'request': request,
                                    'path': request.path},
                                   context_instance=RequestContext(request),
                                   response_format=response_format))
Block with objects links
dataset/ETHPy150Open treeio/treeio/treeio/core/templatetags/object.py/link_block