@contextfunction
def tags_box(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']

    tags = object.tags.all()
    form = None
    if 'tags-edit' in request.GET:
        if request.POST.get('tags_object', 0) == unicode(object.id):
            form = TagsForm(tags, request.POST)
            if form.is_valid():
                if 'multicomplete_tags' in request.POST:
                    tag_names = request.POST.get(
                        'multicomplete_tags').split(',')
                    new_tags = []
                    for name in tag_names:
                        name = name.strip()
                        if name:
                            try:
                                tag = Tag.objects.get(name=name)
                            except Tag.DoesNotExist:
                                tag = Tag(name=name)
                                tag.save()
                            new_tags.append(tag)
                else:
                    new_tags = form.is_valid()

                object.tags.clear()
                for tag in new_tags:
                    object.tags.add(tag)
                tags = object.tags.all()
                form = None
        else:
            form = TagsForm(tags)

    context = {'object': object,
               'tags': tags,
               'form': form,
               'editlink': request.path + '?tags-edit'}

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

    return Markup(render_to_string('core/tags/tags_box', context,
                                   context_instance=RequestContext(request),
                                   response_format=response_format))
dataset/ETHPy150Open treeio/treeio/treeio/core/templatetags/object.py/tags_box/original