@login_required
def display_resource(request, id):
    res = Resource.objects.get(pk=id)
    file = res.content.path.split("/")[-1]
    opts = {'object':res,'file':file}
    ext = opts['file'].split(".")[-1]
    opts['type'] = 'file'
    if ext in IMAGE_EXTS:
        opts['type'] = "image"
    elif ext in ZIP_EXTS:
        try:
            opts['type'] = "zip"
            zf = ZipFile(res.content.path,'r')
            opts['files_list'] = zf.namelist()
            zf.close()
        except IOError:
            opts['type'] = "file"
    else:
        try:
            lexer = get_lexer_for_filename(file)
            f = open(res.content.path,'r')
            data = f.read()
            f.close()
            opts['highlighted_code'] = highlight(data,lexer,HtmlFormatter())
            opts['type'] = "code"
        except ClassNotFound:
            opts['type'] = "file"
        except __HOLE__:
            opts['type'] = "file"

    return render_to_response('lifeflow/editor/resource.html',opts,RequestContext(request, {}))
dataset/ETHPy150Open lethain/lifeflow/editor/views.py/display_resource