def markup_content(obj, field, markup_template='supertagging/markup.html'):
    """
    Takes all the items (SuperTaggedItems), and retrieves all the 'instances' to 
    embed the markup_template.
    """
    ctype = ContentType.objects.get_for_model(obj)
    items = SuperTaggedItem.objects.filter(
        content_type__pk=ctype.pk, object_id=obj.pk, 
        relevance__gte=settings.MIN_RELEVANCE_MARKUP).select_related()
    
    value = getattr(obj, field, '')
    full = []
    for item in items:
        if not item.instances:
            continue
        i = item.instances
        skip = False
        for v in i:
            if isinstance(v, list):
                # TODO: figure out a better way to handle list of dicts
                skip = True
                continue
            if isinstance(v, dict):
                v['supertag'] = item.tag
                
        if not skip:
            full.extend(i)

    # Sort the list by the inner dict offset value in reverse
    full.sort(tag_instance_cmp, reverse=True)
    
    for n, i in enumerate(full):
        if 'offset' in i and 'length' in i and i in 'exact':
            off, le, act_val = i['offset'], i['length'], i['exact']
            if act_val.lower() in settings.MARKUP_EXCLUDES:
                continue
        else:
            continue
            
        # This tests to make sure the next tag does
        # not overlap the current tag
        if n != 0:
            if 'offset' in full[n-1]:
                prev_off = full[n-1]['offset']
                if ((off+1)+le) > prev_off:
                    continue
                    
        # Validate that the data matches the data returned by calais
        if not value[off:(off+le)] == act_val:
            raise FailedMarkupValidation(
                "Markup failed validation: Offset: %s: \"%s\" didn't match \"%s\"" % (off, value[off:(off+le)], act_val))
            break
            
        tag = i['supertag']
        val = render_to_string(markup_template, {'tag': tag, 'actual_value': act_val})
        pre, suf, repl = '','',''
        
        pre = value[:off]
        suf = value[(off+le):]
        repl = value[off:(off+le)]
        
        value = pre+val+suf
        
    return value
dataset/ETHPy150Open callowayproject/django-supertagging/supertagging/markup.py/markup_content/swapped operands of `in`