Exemplo n.º 1
0
def modify_name(request, share, subdir=None):
    import os
    form = RenameForm(request.POST)
    data = json_form_validate(form)
    if form.is_valid():
        if subdir is None:
            from_path = os.path.join(share.get_path(),
                                     form.cleaned_data['from_name'])
            to_path = os.path.join(share.get_path(),
                                   form.cleaned_data['to_name'])
        else:
            from_path = os.path.join(share.get_path(), subdir,
                                     form.cleaned_data['from_name'])
            to_path = os.path.join(share.get_path(), subdir,
                                   form.cleaned_data['to_name'])
        os.rename(from_path, to_path)
        data['objects'] = [{
            'from_name': form.cleaned_data['from_name'],
            'to_name': form.cleaned_data['to_name']
        }]
        ShareLog.create(
            share=share,
            user=request.user,
            action=ShareLog.ACTION_RENAMED,
            text='"%s" renamed to "%s"' %
            (form.cleaned_data['from_name'], form.cleaned_data['to_name']),
            paths=[from_path],
            subdir=subdir)
    return json_response(data)
Exemplo n.º 2
0
def create_folder(request, share, subdir=None):
    form = FolderForm(request.POST)
    data = json_form_validate(form)
    if form.is_valid():
        folder_path = share.create_folder(form.cleaned_data['name'],subdir)
        (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(folder_path)
        data['objects']=[{'name':form.cleaned_data['name'],'modified':datetime.datetime.fromtimestamp(mtime).strftime("%m/%d/%Y %I:%M %p")}]
        ShareLog.create(share=share,user=request.user,action=ShareLog.ACTION_FOLDER_CREATED,paths=[form.cleaned_data['name']],subdir=subdir)
        return json_response(data)
    else:
        return json_error([error for name, error in form.errors.items()])
Exemplo n.º 3
0
def create_folder(request, share, subdir=None):
    form = FolderForm(request.POST)
    data = json_form_validate(form)
    if form.is_valid():
        folder_path = share.create_folder(form.cleaned_data['name'],subdir)
        (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime) = os.stat(folder_path)
        data['objects']=[{'name':form.cleaned_data['name'],'modified':datetime.datetime.fromtimestamp(mtime).strftime("%m/%d/%Y %I:%M %p")}]
        ShareLog.create(share=share,user=request.user,action=ShareLog.ACTION_FOLDER_CREATED,paths=[form.cleaned_data['name']],subdir=subdir)
        return json_response(data)
    else:
        return json_error([error for name, error in form.errors.items()])
Exemplo n.º 4
0
def modify_name(request, share, subdir=None):
    import os
    form = RenameForm(request.POST)
    data = json_form_validate(form)
    if form.is_valid():
        if subdir is None:
            from_path = os.path.join(share.get_path(),form.cleaned_data['from_name'])
            to_path = os.path.join(share.get_path(),form.cleaned_data['to_name'])
        else:
            from_path = os.path.join(share.get_path(),subdir,form.cleaned_data['from_name'])
            to_path = os.path.join(share.get_path(),subdir,form.cleaned_data['to_name'])
        os.rename(from_path, to_path)
        data['objects']=[{'from_name':form.cleaned_data['from_name'],'to_name':form.cleaned_data['to_name']}]
    ShareLog.create(share=share,user=request.user,action=ShareLog.ACTION_RENAMED,text='"%s" renamed to "%s"'%(form.cleaned_data['from_name'],form.cleaned_data['to_name']),paths=[form.cleaned_data['to_name']],subdir=subdir)
    return json_response(data)