Beispiel #1
0
def mkln(request, url=None):
    "Make a new link at the current url."

    url = utils.clean_path(url)
    full_path = os.path.join(utils.get_document_root(), url)

    if request.method == 'POST': 
        form = forms.CreateLinkForm(full_path, None, full_path, request.POST) 

        if form.is_valid(): 
            src = os.path.join(full_path, form.cleaned_data['link'])
            dest = os.path.join(full_path, form.cleaned_data['name'])
            
            try:
                relative = os.path.relpath(src, full_path)
            except AttributeError:
                relative = utils.relpath(src, full_path)

            os.symlink(relative, dest)

            obj_path = os.path.join(url, form.cleaned_data['link'])
            
            obj, created = models.File.objects.get_or_create(path=obj_path, type=models.File.S_IFLNK) 
            
            utils.log_addition(request, obj)

            return redirect('admin_file_manager_list', url=url)
    else:
        form = forms.CreateLinkForm(full_path, None, full_path)

    return render_to_response("admin/file_manager/mkln.html", 
                              {'form': form, 'url': url,},
                              context_instance=template.RequestContext(request))
Beispiel #2
0
def move(request, url=None):
    """
        Move file/directory to a new location.
    """

    # Not really happy about the l/rstrips.
    url = utils.clean_path(url)

    parent = '/'.join(url.split('/')[:-1])
    full_parent = os.path.join(utils.get_document_root(), parent).rstrip('/')
    full_path = os.path.join(utils.get_document_root(), url)
    directory = url.replace(parent, "", 1).lstrip('/')

    if request.method == 'POST':
        form = forms.DirectoryForm(directory, full_path, request.POST)

        if form.is_valid():
            new = os.path.join(form.cleaned_data['parent'], directory)

            if os.path.islink(full_path):

                src = os.readlink(full_path)
                if not os.path.isabs(src):
                    src = os.path.join(os.path.dirname(full_path), src)

                try:
                    relative = os.path.relpath(src,
                                               form.cleaned_data['parent'])
                except AttributeError:
                    relative = utils.relpath(src, form.cleaned_data['parent'])

                os.remove(full_path)  # Remove original link.
                os.symlink(relative, new)  # Create new link.

                # FIXME: Log delete.

            else:
                os.rename(full_path, new)  #Rename the directory

                # FIXME: Log delete.

            return redirect('admin_file_manager_list', url=parent)
    else:
        form = forms.DirectoryForm(directory,
                                   full_path,
                                   initial={'parent': full_parent})

    return render_to_response(
        "admin/file_manager/move.html", {
            'form': form,
            'url': url,
            'current': "/%s" % parent,
            'directory': os.path.isdir(full_path)
        },
        context_instance=template.RequestContext(request))
Beispiel #3
0
def move(request, url=None):
    """
        Move file/directory to a new location.
    """

    # Not really happy about the l/rstrips.
    url = utils.clean_path(url)

    parent = '/'.join(url.split('/')[:-1])
    full_parent = os.path.join(utils.get_document_root(), parent).rstrip('/')
    full_path = os.path.join(utils.get_document_root(), url)
    directory = url.replace(parent, "", 1).lstrip('/')

    if request.method == 'POST': 
        form = forms.DirectoryForm(directory, full_path, request.POST) 

        if form.is_valid(): 
            new = os.path.join(form.cleaned_data['parent'], directory)

            if os.path.islink(full_path):

                src = os.readlink(full_path)
                if not os.path.isabs(src):
                    src = os.path.join(os.path.dirname(full_path), src)

                try:
                    relative = os.path.relpath(src, form.cleaned_data['parent'])
                except AttributeError:
                    relative = utils.relpath(src, form.cleaned_data['parent'])

                os.remove(full_path) # Remove original link.
                os.symlink(relative, new) # Create new link.
        
                # FIXME: Log delete.

            else:
                os.rename(full_path, new) #Rename the directory
                
                # FIXME: Log delete.

            return redirect('admin_file_manager_list', url=parent)
    else:
        form = forms.DirectoryForm(directory, full_path, initial={'parent':full_parent}) 

    return render_to_response("admin/file_manager/move.html", 
                              {'form': form, 'url': url,
                               'current': "/%s" % parent,
                               'directory': os.path.isdir(full_path)},
                              context_instance=template.RequestContext(request))
Beispiel #4
0
def mkln(request, url=None):
    "Make a new link at the current url."

    url = utils.clean_path(url)
    full_path = os.path.join(utils.get_document_root(), url)

    if request.method == 'POST':
        form = forms.CreateLinkForm(full_path, None, full_path, request.POST)

        if form.is_valid():
            src = os.path.join(full_path, form.cleaned_data['link'])
            dest = os.path.join(full_path, form.cleaned_data['name'])

            try:
                relative = os.path.relpath(src, full_path)
            except AttributeError:
                relative = utils.relpath(src, full_path)

            os.symlink(relative, dest)

            obj_path = os.path.join(url, form.cleaned_data['link'])

            obj, created = models.File.objects.get_or_create(
                path=obj_path, type=models.File.S_IFLNK)

            utils.log_addition(request, obj)

            return redirect('admin_file_manager_list', url=url)
    else:
        form = forms.CreateLinkForm(full_path, None, full_path)

    return render_to_response(
        "admin/file_manager/mkln.html", {
            'form': form,
            'url': url,
        },
        context_instance=template.RequestContext(request))