Beispiel #1
0
def post_edit_form(request, blog_slug, post_id):
    if not request.user.is_authenticated():
        return redirect('/accounts/login/?next=/blogs/'+blog_slug+'/posts/'+str(post_id)+'/edit/')

    print request.user

    if request.method == 'POST':
        post = Post.objects.get(id=post_id)
        f = BlogPostForm(request.POST, instance=post)
        if f.is_valid():
            post = f.save()
            messages.add_message(request, messages.INFO, 'This post has been saved.')
            return redirect('/blogs/'+ blog_slug +'/posts/'+ post_id)
    else:
        post = Post.objects.get(id=post_id)
        f = BlogPostForm(instance=post)

    ctx = RequestContext(request, {'form': f.as_table(), 'blog_slug': blog_slug, 'post_id': post_id})
    return render_to_response('planetarium/post_edit_form.html', ctx)
Beispiel #2
0
def post_new_form(request, blog_slug):
    if not request.user.is_authenticated():
        messages.error(request, 'Please log in first.')
        return redirect('/')

    if request.method == 'POST':
        f = BlogPostForm(request.POST)
        if f.is_valid():
            post = f.save(commit=False)
            blog = Blog.objects.get(slug=blog_slug)
            author = request.user
            post.blog = blog
            post.author = author
            post.save()
            messages.add_message(request, messages.INFO, 'New post has been saved.')
            return redirect('/blogs/'+ blog_slug +'/posts/'+ str(post.id))
    else:
        f = BlogPostForm()

    ctx = RequestContext(request, {'form': f.as_table(), 'blog_slug': blog_slug})
    return render_to_response('planetarium/post_new_form.html', ctx)