示例#1
0
def comment_post(request, post_id):

    post = get_object_or_404(Post, id=post_id)
    reply_form = ReplyForm()

    if request.method == 'GET':
        format_post(request, post)
        comment_form = CommentForm()
    else:
        if not request.user.is_authenticated():
            path = request.get_full_path()
            return redirect_to_login(path)

        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            comment_form.save(request.user, post)
            return HttpResponseRedirect(
                reverse('news:comment', kwargs={'post_id': post_id}))

    comments = Comment.objects.filter(post=post, parent=None)

    return render(
        request, 'news/comment.html', {
            'comment_form': comment_form,
            'reply_form': reply_form,
            'post': post,
            'show_index': False,
            'comments': comments,
        })
示例#2
0
def comment_post(request, post_id):

    post = get_object_or_404(Post, id=post_id)
    reply_form = ReplyForm()

    if request.method == 'GET':
        format_post(request, post)
        comment_form = CommentForm()
    else:
        if not request.user.is_authenticated():
            path = request.get_full_path()
            return redirect_to_login(path)

        comment_form = CommentForm(request.POST)
        if comment_form.is_valid():
            comment_form.save(request.user, post)
            return HttpResponseRedirect(reverse('news:comment', kwargs={
                'post_id': post_id
            }))

    comments = Comment.objects.filter(post=post, parent=None)

    return render(request, 'news/comment.html', {
        'comment_form': comment_form,
        'reply_form': reply_form,
        'post': post,
        'show_index': False,
        'comments': comments,
    })
示例#3
0
def index(request, cur_page_num=1, order_by=None):
    cur_page_num = int(cur_page_num)
    num_per_page = 30

    posts = Post.objects.all()
    if order_by:
        posts = posts.order_by(order_by)
    paged_object = get_paged_object(posts, cur_page_num, num_per_page)
    for post in paged_object.object_list:
        format_post(request, post)

    return render(request, 'news/list.html', {
        'paged_object': paged_object,
        'start_index': num_per_page * (cur_page_num - 1),
        'show_index': True,
    })
示例#4
0
def index(request, cur_page_num=1, order_by=None):
    cur_page_num = int(cur_page_num)
    num_per_page = 30

    posts = Post.objects.all()
    if order_by:
        posts = posts.order_by(order_by)
    paged_object = get_paged_object(posts, cur_page_num, num_per_page)
    for post in paged_object.object_list:
        format_post(request, post)

    return render(
        request, 'news/list.html', {
            'paged_object': paged_object,
            'start_index': num_per_page * (cur_page_num - 1),
            'show_index': True,
        })