Beispiel #1
0
def mkdir(request, path):
    context = auto_context(**locals())

    if not path.exists() or not path.is_dir():
        return render_to_response('mediafiles/404.html', context)

    if not path.is_writeable():
        return render_to_response('mediafiles/403.html', context)

    add_another = request.REQUEST.get('_addanother', False)

    if add_another:
        redirect_to = request.path
    else:
        redirect_to = request.REQUEST.get('next', None)
        if redirect_to is None or ' ' in redirect_to or '\\' in redirect_to:
            redirect_to = path.get_absolute_url()

    if request.method == 'POST':
        form = MakeDirectoryForm(request.POST, path=path)
        if form.is_valid():
            return HttpResponseRedirect(redirect_to)
    else:
        form = MakeDirectoryForm(path=path)

    context.update({'form': form})
    return render_to_response('mediafiles/mkdir.html', context)
Beispiel #2
0
def edit(request, path):
    context = auto_context(**locals())

    if not path.exists():
        return render_to_response('mediafiles/404.html', context)

    if not path.is_readable():
        return render_to_response('mediafiles/403.html', context)

    if path.is_dir():
        return HttpResponseRedirect(reverse('mediafiles_rename',
                                            kwargs={'path': path}))

    continue_editing = request.POST.get('_continue', False)

    if continue_editing:
        redirect_to = request.path
    else:
        redirect_to = request.REQUEST.get('next', None)
        if redirect_to is None or ' ' in redirect_to or '\\' in redirect_to:
            redirect_to = path.get_absolute_url()

    if request.method == 'POST':
        form = EditFileForm(request.POST, path=path)
        if form.is_valid():
            return HttpResponseRedirect(redirect_to)
    else:
        form = EditFileForm(path=path)

    context.update({'form': form})
    return render_to_response('mediafiles/edit.html', context)
Beispiel #3
0
def rename(request, path):
    context = auto_context(**locals())

    if path.is_root():
        return HttpResponseRedirect(path.get_absolute_url())

    if not path.exists():
        return render_to_response('mediafiles/404.html', context)

    redirect_to = request.REQUEST.get('next', None)

    if redirect_to is None or ' ' in redirect_to or '\\' in redirect_to:
        redirect_to = path.parent.get_absolute_url()

    if request.method == 'POST':
        if not 'oldname' in request.POST:
            request.POST.update({'oldname': path.name})

        form = RenamePathForm(request.POST, path=path)
        if form.is_valid():
            return HttpResponseRedirect(redirect_to)
    else:
        form = RenamePathForm(initial={'oldname': path.name}, path=path)

    context.update({'form': form})
    return render_to_response('mediafiles/rename.html', context)
Beispiel #4
0
def mkdir(request, path):
    context = auto_context(**locals())

    if not path.exists() or not path.is_dir():
        return render_to_response('mediafiles/404.html', context)

    if not path.is_writeable():
        return render_to_response('mediafiles/403.html', context)

    add_another = request.REQUEST.get('_addanother', False)

    if add_another:
        redirect_to = request.path
    else:
        redirect_to = request.REQUEST.get('next', None)
        if redirect_to is None or ' ' in redirect_to or '\\' in redirect_to:
            redirect_to = path.get_absolute_url()

    if request.method == 'POST':
        form = MakeDirectoryForm(request.POST, path=path)
        if form.is_valid():
            return HttpResponseRedirect(redirect_to)
    else:
        form = MakeDirectoryForm(path=path)

    context.update({'form': form})
    return render_to_response('mediafiles/mkdir.html', context)
Beispiel #5
0
def edit(request, path):
    context = auto_context(**locals())

    if not path.exists():
        return render_to_response('mediafiles/404.html', context)

    if not path.is_readable():
        return render_to_response('mediafiles/403.html', context)

    if path.is_dir():
        return HttpResponseRedirect(
            reverse('mediafiles_rename', kwargs={'path': path}))

    continue_editing = request.POST.get('_continue', False)

    if continue_editing:
        redirect_to = request.path
    else:
        redirect_to = request.REQUEST.get('next', None)
        if redirect_to is None or ' ' in redirect_to or '\\' in redirect_to:
            redirect_to = path.get_absolute_url()

    if request.method == 'POST':
        form = EditFileForm(request.POST, path=path)
        if form.is_valid():
            return HttpResponseRedirect(redirect_to)
    else:
        form = EditFileForm(path=path)

    context.update({'form': form})
    return render_to_response('mediafiles/edit.html', context)
Beispiel #6
0
def rename(request, path):
    context = auto_context(**locals())

    if path.is_root():
        return HttpResponseRedirect(path.get_absolute_url())

    if not path.exists():
        return render_to_response('mediafiles/404.html', context)

    redirect_to = request.REQUEST.get('next', None)

    if redirect_to is None or ' ' in redirect_to or '\\' in redirect_to:
        redirect_to = path.parent.get_absolute_url()

    if request.method == 'POST':
        if not 'oldname' in request.POST:
            request.POST.update({'oldname': path.name})

        form = RenamePathForm(request.POST, path=path)
        if form.is_valid():
            return HttpResponseRedirect(redirect_to)
    else:
        form = RenamePathForm(initial={'oldname': path.name}, path=path)

    context.update({'form': form})
    return render_to_response('mediafiles/rename.html', context)
Beispiel #7
0
def explorer(request, path):
    context = auto_context(**locals())

    if not path.exists():
        return render_to_response('mediafiles/404.html', context)

    if not path.is_readable():
        return render_to_response('mediafiles/403.html', context)

    return render_to_response('mediafiles/explorer.html', context)
Beispiel #8
0
def explorer(request, path):
    context = auto_context(**locals())

    if not path.exists():
        return render_to_response('mediafiles/404.html', context)

    if not path.is_readable():
        return render_to_response('mediafiles/403.html', context)

    return render_to_response('mediafiles/explorer.html', context)