Пример #1
0
def post(request, pk):
    """Single post with comments and a comment form."""
    post = Post.objects.get(pk=int(pk))
    comments = Comment.objects.filter(post=post)
    d = dict(post=post, comments=comments, form=CommentForm(), user=request.user, months=mkmonth_lst())
    d.update(csrf(request))
    print_sql(connection.queries)
    return render_to_response("blog/post.html", d)
Пример #2
0
def main(request):
    """Main listing."""
    posts_list = Post.objects.all().order_by("-published")
    posts = paginator(request, posts_list)
    print_sql(connection.queries)
    return render_to_response(
        "blog/list.html",
        dict(posts=posts, user=request.user, months=mkmonth_lst()))
Пример #3
0
def month(request, year, month):
    """Monthly archive."""
    posts_list = Post.objects.filter(published__year=year, published__month=month)
    posts = paginator(request, posts_list)
    print_sql(connection.queries)
    return render_to_response(
        "blog/list.html", dict(posts=posts, user=request.user, months=mkmonth_lst(), archive=True)
    )
Пример #4
0
def month(request, year, month):
    """Monthly archive."""
    posts_list = Post.objects.filter(published__year=year,
                                     published__month=month)
    posts = paginator(request, posts_list)
    print_sql(connection.queries)
    return render_to_response(
        "blog/list.html",
        dict(posts=posts,
             user=request.user,
             months=mkmonth_lst(),
             archive=True))
Пример #5
0
def delete_comment(request, post_pk, comment_pk=None):
    """Delete comment(s) with primary key `comment_pk` or with pks in POST."""
    if request.user.is_staff:
        if not comment_pk: pklst = request.POST.getlist("delete")
        else: pklst = [comment_pk]

        for pk in pklst:
            Comment.objects.get(pk=pk).delete()

    print_sql(connection.queries)
    return HttpResponseRedirect(
        reverse("KKlog.blog.views.post", args=[post_pk]))
Пример #6
0
def delete_comment(request, post_pk, comment_pk=None):
    """Delete comment(s) with primary key `comment_pk` or with pks in POST."""
    if request.user.is_staff:
        if not comment_pk:
            pklst = request.POST.getlist("delete")
        else:
            pklst = [comment_pk]

        for pk in pklst:
            Comment.objects.get(pk=pk).delete()

    print_sql(connection.queries)
    return HttpResponseRedirect(reverse("KKlog.blog.views.post", args=[post_pk]))
Пример #7
0
def post(request, pk):
    """Single post with comments and a comment form."""
    post = Post.objects.get(pk=int(pk))
    comments = Comment.objects.filter(post=post)
    d = dict(
        post=post,
        comments=comments,
        form=CommentForm(),
        user=request.user,
        months=mkmonth_lst(),
    )
    d.update(csrf(request))
    print_sql(connection.queries)
    return render_to_response("blog/post.html", d)
Пример #8
0
def add_comment(request, post_pk):
    """Add a new comment."""
    p = request.POST

    if p.has_key("body") and p["body"]:
        author = "Anonymous"
        if p["author"]:
            author = p["author"]

        comment = Comment(post=Post.objects.get(pk=post_pk))
        cf = CommentForm(p, instance=comment)
        cf.fields["author"].required = False

        comment = cf.save(commit=False)
        comment.author = author
        comment.save()
    print_sql(connection.queries)
    return HttpResponseRedirect(reverse("KKlog.blog.views.post", args=[post_pk]))
Пример #9
0
def add_comment(request, post_pk):
    """Add a new comment."""
    p = request.POST

    if p.has_key("body") and p["body"]:
        author = "Anonymous"
        if p["author"]: author = p["author"]

        comment = Comment(post=Post.objects.get(pk=post_pk))
        cf = CommentForm(p, instance=comment)
        cf.fields["author"].required = False

        comment = cf.save(commit=False)
        comment.author = author
        comment.save()
    print_sql(connection.queries)
    return HttpResponseRedirect(
        reverse("KKlog.blog.views.post", args=[post_pk]))
Пример #10
0
def main(request):
    """Main listing."""
    posts_list = Post.objects.all().order_by("-published")
    posts = paginator(request, posts_list)
    print_sql(connection.queries)
    return render_to_response("blog/list.html", dict(posts=posts, user=request.user, months=mkmonth_lst()))