예제 #1
0
def view_directory(request, path):
    parent_path = fs.parent_path(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:
        context_dirs.append({'path': single.path,
            'name': fs.file_name(single.path)})
    files = File.objects.filter(path=d)
    for single in files:
        file_path = single.path.path + '/' + single.name
        context_files.append({'path': file_path,
            'name': single.name})
    response = render(request, 'directory.html', {'remote': REMOTE_PREFIX, 'dirs': context_dirs,
                  'files': context_files})
    return response
예제 #2
0
def bulk_delete(request):
    if request.method == 'POST':
        report = []
        file_data= request.POST['files']
        files = json.load(file_data)

        for entry in files:            
            remote_path = request.POST['path']
            name = fs.file_name(remote_path)
            remote_parent = fs.parent_path(remote_path)
            try:
                remote_dir = Directory.objects.get(path=remote_parent)
                tmp_file = File.objects.get(name=name, path=remote_dir)
                tmp_file.delete()
                report.append({'status': '1', 'name': name,
                    'message': 'File delete succesfully.'})
            except:
                report.append({'status': '0', 'name': name,
                    'message': 'Path does not exist.'})
    else:
        report.append({'status': '0',
            'message': 'Use POST for deleting a file.'})

    response = render(request, 'response.xml', {'report': report},
            content_type='text/xml')
    return response
예제 #3
0
def view_directory(request, path):
    parent_path = fs.parent_path(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:
        context_dirs.append({'path': single.path,
            'name': fs.file_name(single.path)})
    files = File.objects.filter(path=d)
    for single in files:
        file_path = single.path.path + '/' + single.name
        context_files.append({'path': file_path,
            'name': single.name})
    
    response = render(request, 'directory.html', {'dir_path': path, 
    'remote': REMOTE_PREFIX, 'dirs': context_dirs,
    'files': context_files})
    return response
예제 #4
0
def handle_upload(request):
    if request.method == 'POST':
        remote_path = request.POST['path']
        date_str = str(request.POST['last_modified'])
        last_modified = datetime.strptime(date_str, '%Y-%m-%d')
        f = request.FILES['file']
        temp_path = fs.save_from_upload(remote_path, f)
        file_info = fs.file_info(temp_path)
        remote_parent = fs.parent_path(remote_path)
        
        remote_dir = create_hierarchy(remote_parent)
        new_file = File(name=file_info['name'], path=remote_dir,
                    size=file_info['size'],
                    last_modified=last_modified)
        new_file.save()
        storage_ebs.upload_file(temp_path, remote_path)
        response = render(request, 'response.xml',
                    {'status': '1', 'message': 'File uploaded successfully.'},
                    content_type='text/xml')
    else:
        response = render(request, 'response.xml',
                   {'status': '0', 'message': 'Use POST for file uploads.'},
                   content_type='text/xml')
    return response