def render_inline(inline):
    # Look for inline model type, 'app.model'
    if inline.name == 'inline':
        model_string = inline.get('type', None)
    else:
        model_string = inline.get('data-inline-type', None)

    if not model_string:
        if settings.DEBUG:
            raise TemplateSyntaxError, "Couldn't find a model attribute in the <%s> tag." % inline.name
        else:
            return ''
    app_label, model_name = model_string.split('.')

    # Look for content type
    try:
        content_type = ContentType.objects.get(app_label=app_label, model=model_name)
        model = content_type.model_class()
    except ContentType.DoesNotExist:
        if settings.DEBUG:
            raise TemplateSyntaxError, "Inline ContentType not found for '%s.%s'." % (app_label, model_name)
        else:
            return ''

    # Check for an inline class attribute
    inline_class = smart_unicode(inline.get('class', ''))

    inline_attr = get_inline_attr(inline)

    if not inline_attr:
        return ''

    if inline_attr.get("ids", None):
        # The tag has the 'ids' attribute, process accordingly...
        id_list = [int(i) for i in inline_attr["ids"].split(',')]
        obj_list = model.objects.in_bulk(id_list)
        obj_list = list(obj_list[int(i)] for i in id_list)
        context = { 'object_list': obj_list, 'class': inline_class }
    elif inline_attr.get("id", None):
        # The tag has the 'id' attribute, process accordingly...
        try:
            obj = model.objects.get(pk=inline_attr["id"])
        except model.DoesNotExist:
            if settings.DEBUG:
                raise model.DoesNotExist, "%s with pk of '%s' does not exist" % (model_name, inline_attr["id"])
            else:
                return ''
        context = { 'content_type':"%s.%s" % (app_label, model_name), 'object': obj, 'class': inline_class, 'settings': settings }
    elif inline_attr.get("filter", None):
        # The tag has the 'filter' attribute, process accordingly...
        try:
            l = inline_attr["filter"].split(',')
            filterdict = dict()
            for item in l:
                try:
                    # This is just here to raise a ValueError if there is no '='
                    item.index('=')
                    parts = item.split('=')
                    ## This should work for text, Need to test for all sorts of values
                    # Note: Potentially dangerous use of eval
                    filterdict[str(parts[0])] = eval(parts[1])
                except ValueError:
                    pass
            obj_list = list(model.objects.filter(**filterdict))
            context = { 'object_list': obj_list, 'class': inline_class }
        except KeyError:
            if settings.DEBUG:
                raise TemplateSyntaxError, "The <inline> filter attribute is missing or invalid."
            else:
                return ''
        except ValueError:
            if settings.DEBUG:
                raise TemplateSyntaxError, inline_attr["filter"] + ' is bad, dummy.'
            else:
                return ''
    else:
        raise ValueError

    # Set Default Template
    template = list()
    if inline.get('template', None):
        template.insert(0, inline.get('template'))
    if inline.get('data-inline-template', None):
        template.insert(0, inline.get('data-inline-template'))

    template.extend(["inlines/%s_%s.html" % (app_label, model_name), "inlines/default.html"])

    rendered_inline = {'template': template, 'context': context}

    return rendered_inline
Helper to print a traceback from the timed code.
dataset/ETHPy150Open issackelly/django-improved-inlines/improved_inlines/parser.py/render_inline--crossover with--dataset/ETHPy150Open deanhiller/databus/webapp/play1.3.x/python/Lib/timeit.py/Timer.print_exc