예제 #1
0
파일: views.py 프로젝트: klacia/KKlog
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
파일: views.py 프로젝트: klacia/KKlog
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
파일: views.py 프로젝트: klacia/KKlog
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
파일: views.py 프로젝트: klacia/KKlog
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
파일: views.py 프로젝트: klacia/KKlog
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()))