예제 #1
0
def index(request):
    ctx_data = {'dirs': [], 'files': []}

    if DIR_BROWSE_FALLBACK == True:
        ctx_data = dir_fallback('.')
    else:
        path_regex = '^' + '/[^/]+$'
        context_dirs = []
        try:
            dirs = Directory.objects.filter(path__regex=path_regex)
        except:
            pass

        try:
            directory = Directory.objects.get(path='/')
            files = File.objects.filter(path=directory)
        except:
            pass

        for single in dirs:
            ctx_data['dirs'].append({'path': single.path[1:],
                'name': os.path.basename('/' + single.path)})

        for single in files:
            ctx_data['files'].append({'path': os.path.join(single.path.path[1:], single.name), 'name': single.name})

    ctx_data['remote'] = REMOTE_PREFIX
    ctx_data['site_prefix'] = SITE_PREFIX
    response = render(request, 'index.html', ctx_data)
    return response
예제 #2
0
def view_directory(request, path):
    ctx_data = {'dirs': [], 'files': []}

    path = '/' + path

    if DIR_BROWSE_FALLBACK == True:
        ctx_data = dir_fallback(path)

    else:    
        parent_path = os.path.dirname(path)
        context_files = []
        context_dirs = []
        dirs = []
        files = []
        path_regex = '^' + path + '/[^/]+$'
        try:
            d = Directory.objects.get(path=path)
        except:
            return HttpResponse('Not Found')
        try:
            dirs = Directory.objects.filter(path__regex=path_regex)
        except:
            pass
        for single in dirs:
            ctx_data['dirs'].append({'path': single.path[1:],
                'name': os.path.basename(single.path)})
        files = File.objects.filter(path=d)
        for single in files:
            file_path = os.path.join(single.path.path[1:], single.name)
            ctx_data['files'].append({'path': file_path,
                'name': single.name})
        
    ctx_data['remote'] = REMOTE_PREFIX
    ctx_data['dir_path'] = path[1:]
    ctx_data['site_prefix'] = SITE_PREFIX
    response = render(request, 'directory.html', ctx_data)
    return response