示例#1
0
文件: views.py 项目: 5n1p/treeio
def file_edit(request, file_id, response_format='html'):
    "File edit page"

    file = get_object_or_404(File, pk=file_id)
    if not request.user.get_profile().has_permission(file, mode='w'):
        return user_denied(request, message="You don't have access to this File")

    if request.POST:
        if not 'cancel' in request.POST:
            form = FileForm(
                request.user.get_profile(), None, request.POST, request.FILES, instance=file)
            if form.is_valid():
                file = form.save()
                return HttpResponseRedirect(reverse('documents_file_view', args=[file.id]))
        else:
            return HttpResponseRedirect(reverse('documents_file_view', args=[file.id]))

    else:
        form = FileForm(request.user.get_profile(), None, instance=file)

    context = _get_default_context(request)
    context.update({'form': form,
                    'file': file})

    return render_to_response('documents/file_edit', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#2
0
文件: views.py 项目: 5n1p/treeio
def file_upload_typed(request, folder_id=None, response_format='html'):
    "File upload to preselected folder"

    folder = None
    if folder_id:
        folder = get_object_or_404(Folder, pk=folder_id)
        if not request.user.get_profile().has_permission(folder, mode='x'):
            folder = None

    if request.POST:
        if not 'cancel' in request.POST:
            form = FileForm(
                request.user.get_profile(), folder_id, request.POST, request.FILES)
            if form.is_valid():
                file = form.save()
                file.set_user_from_request(request)
                return HttpResponseRedirect(reverse('documents_file_view', args=[file.id]))
        else:
            return HttpResponseRedirect(reverse('document_index'))
    else:
        form = FileForm(request.user.get_profile(), folder_id)

    context = _get_default_context(request)
    context.update({'form': form,
                    'folder': folder})

    return render_to_response('documents/file_upload_typed', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#3
0
def file_edit(request, file_id, response_format='html'):
    "File edit page"

    file = get_object_or_404(File, pk=file_id)
    if not request.user.get_profile().has_permission(file, mode='w'):
        return user_denied(request,
                           message="You don't have access to this File")

    if request.POST:
        if not 'cancel' in request.POST:
            form = FileForm(request.user.get_profile(),
                            None,
                            request.POST,
                            request.FILES,
                            instance=file)
            if form.is_valid():
                file = form.save()
                return HttpResponseRedirect(
                    reverse('documents_file_view', args=[file.id]))
        else:
            return HttpResponseRedirect(
                reverse('documents_file_view', args=[file.id]))

    else:
        form = FileForm(request.user.get_profile(), None, instance=file)

    context = _get_default_context(request)
    context.update({'form': form, 'file': file})

    return render_to_response('documents/file_edit',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#4
0
def file_upload_typed(request, folder_id=None, response_format='html'):
    "File upload to preselected folder"

    folder = None
    if folder_id:
        folder = get_object_or_404(Folder, pk=folder_id)
        if not request.user.get_profile().has_permission(folder, mode='x'):
            folder = None

    if request.POST:
        if not 'cancel' in request.POST:
            form = FileForm(request.user.get_profile(), folder_id,
                            request.POST, request.FILES)
            if form.is_valid():
                file = form.save()
                file.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('documents_file_view', args=[file.id]))
        else:
            return HttpResponseRedirect(reverse('document_index'))
    else:
        form = FileForm(request.user.get_profile(), folder_id)

    context = _get_default_context(request)
    context.update({'form': form, 'folder': folder})

    return render_to_response('documents/file_upload_typed',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#5
0
def file_upload(request, response_format='html'):
    "New file form"

    if request.POST:
        if not 'cancel' in request.POST:
            file = File()
            form = FileForm(request.user.get_profile(),
                            None,
                            request.POST,
                            request.FILES,
                            instance=file)
            if form.is_valid():
                file = form.save()
                file.set_user_from_request(request)
                return HttpResponseRedirect(
                    reverse('documents_file_view', args=[file.id]))
        else:
            return HttpResponseRedirect(reverse('document_index'))
    else:
        form = FileForm(request.user.get_profile(), None)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('documents/file_upload',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
示例#6
0
def file_upload(request, response_format='html'):
    "New file form"

    if request.POST:  
        if not 'cancel' in request.POST:
            file = File()
            form = FileForm(request.user.get_profile(), None, request.POST, request.FILES, instance=file)
            if form.is_valid():
                file = form.save()
                file.set_user_from_request(request)
                return HttpResponseRedirect(reverse('documents_file_view', args=[file.id]))
        else:
            return HttpResponseRedirect(reverse('document_index'))
    else:
        form = FileForm(request.user.get_profile(), None)
        
    context = _get_default_context(request)
    context.update({'form': form})
    
    return render_to_response('documents/file_upload', context,
                              context_instance=RequestContext(request),
                              response_format=response_format)