Beispiel #1
0
def post_add(request, form_class=PostForm, template_name="socialblog/post_add.html"):
    post_form = form_class(request)
    if request.method == "POST" and post_form.is_valid():
        post = post_form.save(commit=False)
        post.author = request.user
        post.rating = create_rating()
        post.creator_ip = get_client_ip(request)
        post.save()
        messages.success(request, _(u"Successfully created post '%s'") % post.title)

        return redirect(post.get_absolute_url())

    return TemplateResponse(request, template_name, \
        {'post_form': post_form, 'current_user': request.user})
Beispiel #2
0
def post_change_status(request, action, object_id):
    post = get_object_or_404(Post, pk=object_id)
    if not post.can_edit(request.user):
        messages.error(request, _(u"You can't change status of post that isn't your"))
    else:
        if action == 'draft' and post.status == Post.IS_PUBLIC:
            post.status = Post.IS_DRAFT
        if action == 'public' and post.status == Post.IS_DRAFT:
            post.status = Post.IS_PUBLIC
            post_published.send(sender=Post, post=post)
        post.save()
        messages.success(request, _(u"Successfully change status for post '%s'") % post.title)

    next = request.GET.get('next', post.blog.get_absolute_url())

    return safe_redirect(next, request)
Beispiel #3
0
def post_edit(request, object_id, form_class=PostForm, template_name="socialblog/post_edit.html"):
    post = get_object_or_404(Post, pk=object_id)
    if not post.can_edit(request.user):
        messages.error(request, _(u"You can't edit posts that aren't yours"))
        return redirect(post.blog.get_absolute_url())

    post_form = form_class(request, instance=post)
    if request.method == "POST" and post_form.is_valid():
        post = post_form.save(commit=False)
        post.updated = utcnow()
        post.save()

        messages.success(request, _(u"Successfully updated post '%s'") % post.title)

        return redirect(post.get_absolute_url())

    return TemplateResponse(request, template_name, {"post_form": post_form, "post": post})