Beispiel #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)
Beispiel #2
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)
Beispiel #3
0
def repo_rename(request, username, repo_name):
    '''rename project '''

    repo      = request.repo
    context   = request.context

    form      = RenameForm(request.POST)
    form.repo = repo

    if form.is_valid():

        repo  = form.save()
        messages.success(request, "项目名称修改成功!")

    else:

        form_message(request, form)

    return HttpResponseRedirect(reverse("repo_admin", args=[username, repo.name]))
Beispiel #4
0
def repo_rename(request, username, repo_name):
    '''rename project '''

    repo = request.repo
    context = request.context

    form = RenameForm(request.POST)
    form.repo = repo

    if form.is_valid():

        repo = form.save()
        messages.success(request, "项目名称修改成功!")

    else:

        form_message(request, form)

    return HttpResponseRedirect(
        reverse("repo_admin", args=[username, repo.name]))
Beispiel #5
0
def list_directory(request,share,subdir=None):
    if not share.check_path(subdir=subdir):
        return render(request,'error.html', {"message": "Unable to locate the files.  It is possible that the directory has been moved, renamed, or deleted.","share":share,"subdir":subdir})
    files,directories = list_share_dir(share,subdir=subdir,ajax=request.is_ajax())
    print files
    if request.is_ajax():
        return json_response({'files':files,'directories':directories.values()})
    #Find any shares that point at this directory
    for s in Share.user_queryset(request.user).filter(real_path__in=directories.keys()).exclude(id=share.id):
        directories[s.real_path]['share']=s
    share_perms = share.get_user_permissions(request.user)
    PATH = share.get_path()
    subshare = None
    if subdir is not None:
        PATH = os.path.join(PATH,subdir)
        subshare = Share.objects.filter(parent=share,sub_directory=subdir).first()
    owner = request.user == share.owner
    all_perms = share.get_permissions(user_specific=True)
    shared_users = all_perms['user_perms'].keys()
    shared_groups = [g['group']['name'] for g in all_perms['group_perms']]
    emails = sorted([u.email for u in share.get_users_with_permissions()])
    readme = None
    #The following block is for markdown rendering
    if os.path.isfile(os.path.join(PATH,'README.md')):
        import markdown
        input_file = codecs.open(os.path.join(PATH,'README.md'), mode="r", encoding="utf-8")
        text = input_file.read()
        readme = markdown.markdown(text,extensions=['fenced_code','tables','nl2br'])
        download_base = reverse('download_file',kwargs={'share':share.id,'subpath':subdir if subdir else ''})
        readme = re.sub(r'src="(?!http)',r'src="{0}'.format(download_base),readme)
    return render(request,'list.html', {"session_cookie":request.COOKIES.get('sessionid'),"files":files,"directories":directories.values(),"path":PATH,"share":share,"subshare":subshare,"subdir": subdir,'rsync_url':get_setting('RSYNC_URL',None),'HOST':get_setting('HOST',None),'SFTP_PORT':get_setting('SFTP_PORT',None),"folder_form":FolderForm(),"metadata_form":MetaDataForm(), "rename_form":RenameForm(),"request":request,"owner":owner,"share_perms":share_perms,"all_perms":all_perms,"share_perms_json":json.dumps(share_perms),"shared_users":shared_users,"shared_groups":shared_groups,"emails":emails, "readme":readme})