Exemplo n.º 1
0
def publish(request):
    '''
    Handle the publish of a post,
    return a special 222 code if success, which tells the javascript to guide user.
    '''
    if request.method == 'POST':
        # Get video data, check and save
        form = PostForm(request.POST)
        if form.is_valid():
            new_post = form.save(commit=False)
            new_post.author = request.user
            new_post.save()
            return HttpResponse(status='222')

    form = PostForm()

    return render_to_response('publish.html', {
        'request': request,
        'form': form,
    }, context_instance=RequestContext(request))
Exemplo n.º 2
0
def edit(request, post_id):
    '''
    Handle the edition of a post,
    return a special 222 code if success, which tells the javascript to guide user.
    '''
    post = get_object_or_404(Post, id=post_id)

    if request.user == post.author and request.method == 'POST':
        form = PostForm(request.POST, instance=post)
        if form.is_valid():
            form.save()
            return HttpResponse(status='222')


    form = PostForm(instance=post)

    return render_to_response('edit.html', {
        'request': request,
        'form': form,
    }, context_instance=RequestContext(request))