def researchfiles(request, pathname): try: root = settings.RESEARCH_FILES_ROOT except: raise Http404 r = path.join(root, pathname) if path.isfile(r): return serve_content(r) elif path.isdir(r): dir_contents = filter(lambda c: not c[0] == '.', listdir(r)) dir_contents = map(lambda c: (path.isdir(path.join(r, c)), c), dir_contents) if (len(pathname) > 0) and (not pathname[0] == '/'): pathname = '/' + pathname pathname = path.normpath(pathname) if pathname == '.': pathname = '' levels = pathname.split('/') # Is there a better way than this? if len(pathname) < 2: current_level = 'Research Files' else: current_level = levels[-1] return render_to_response('gedgo/researchfiles.html', {'contents': dir_contents, 'levels': levels, 'path': pathname, 'current_level': current_level}, context_instance=RequestContext(request, site_context(request))) else: raise Http404
def researchfiles(request, pathname): try: root = settings.RESEARCH_FILES_ROOT except: raise Http404 r = path.join(root, pathname) if path.isfile(r): return serve_content(r) elif path.isdir(r): dir_contents = filter(lambda c: not c[0] == '.', listdir(r)) dir_contents = map(lambda c: (path.isdir(path.join(r, c)), c), dir_contents) if (len(pathname) > 0) and (not pathname[0] == '/'): pathname = '/' + pathname pathname = path.normpath(pathname) if pathname == '.': pathname = '' levels = pathname.split('/') # Is there a better way than this? if len(pathname) < 2: current_level = 'Research Files' else: current_level = levels[-1] return render_to_response('gedgo/researchfiles.html', { 'contents': dir_contents, 'levels': levels, 'path': pathname, 'current_level': current_level }, context_instance=RequestContext( request, site_context(request))) else: raise Http404
def research(request, pathname): if storage is None: raise Http404 name = pathname.strip('/') # Serve the content through xsendfile or directly. try: if '.' in name: return serve_content(storage, name) else: directories, files = storage.listdir(name) directories = [__process(name, d, True) for d in directories] files = [__process(name, f, False) for f in files] # Build a depth tree of the directories above this one for # navigation levels = [('Research Files', '')] if name: lp = '' for l in name.split('/'): lp = '%s/%s' % (lp, l) levels.append((l, lp)) return render( request, 'research.html', { 'directories': directories, 'files': files, 'levels': levels } ) except Exception as e: raise e raise Http404
def media(request, file_base_name): filename = path.join(settings.MEDIA_ROOT, file_base_name) return serve_content(filename)