Esempio n. 1
0
def add_file(request):

    """
    Creates a new RepoFile object. The form is modified during validation to
    store the author.
    
    :context: form
    
    .. versionadded:: 0.2b
    """
    file_form = RepoFileForm(request.POST or None, request.FILES or None)
    
    if request.user.is_staff:
        if request.method == 'POST':
            if file_form.is_valid():
                file_form_uncommited = file_form.save(commit=False)
                file_form_uncommited.author = request.user
                file_form_uncommited.save()
                file_form.save_m2m()
                
                return redirect('/')
    else:
        return render_to_response('errors/not_allowed.html',
                                  context_instance=RequestContext(request))
    
    return render_to_response('repository/repofile_add.html', {'form':file_form},
                              context_instance=RequestContext(request))
Esempio n. 2
0
def edit_file(request, file_id):

    """
    """
    cur_file = get_object_or_404(RepoFile, pk=file_id)

    editfile_form = RepoFileForm(request.POST or None, instance=cur_file)
    
    if request.method == "POST":
        if editfile_form.is_valid():
            editfile_form_uncommited = editfile_form.save(commit=False)
            editfile_form_uncommited.author = request.user
            editfile_form_uncommited.save()
            
            return HttpResponseRedirect(reverse('view_file', args=[file_id]))
            
    return render_to_response('repository/repofile_edit.html',
                            {'form': editfile_form, 'file':cur_file},
                                context_instance=RequestContext(request))
def edit_file(request, file_id):
    """
    """
    cur_file = get_object_or_404(RepoFile, pk=file_id)

    editfile_form = RepoFileForm(request.POST or None, instance=cur_file)

    if request.method == "POST":
        if editfile_form.is_valid():
            editfile_form_uncommited = editfile_form.save(commit=False)
            editfile_form_uncommited.author = request.user
            editfile_form_uncommited.save()

            return HttpResponseRedirect(reverse('view_file', args=[file_id]))

    return render_to_response('repository/repofile_edit.html', {
        'form': editfile_form,
        'file': cur_file
    },
                              context_instance=RequestContext(request))
def add_file(request):
    """
    Creates a new RepoFile object. The form is modified during validation to
    store the author.
    
    :context: form
    
    .. versionadded:: 0.2b
    """
    file_form = RepoFileForm(request.POST or None, request.FILES or None)

    if request.user.is_staff:
        if request.method == 'POST':
            if file_form.is_valid():
                file_form_uncommited = file_form.save(commit=False)
                file_form_uncommited.author = request.user
                file_form_uncommited.save()
                file_form.save_m2m()

                return redirect('/')
    else:
        return render_to_response('errors/not_allowed.html',
                                  context_instance=RequestContext(request))

    return render_to_response('repository/repofile_add.html',
                              {'form': file_form},
                              context_instance=RequestContext(request))