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)
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()))
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) )
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))
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]))
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]))
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)
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]))
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]))
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()))