コード例 #1
0
def post_view(request, post_slug, post_id):
    post = Post.get(post_id)
    if not post:
        raise Http404('The post could not be found')

    if post.status != 'PUBLISHED' and post.user_id != request.user.id \
            or post.slug != post_slug:
        raise Http404('The post could not be found.')

    comments = Comment.get_comments(post)
    if post.status != 'DRAFT':
        comment_form = request.user.is_authenticated() and\
            AuthorizedCommentForm or AnonymousCommentForm
        comment_form = comment_form(
            initial={
                'root_ctype_id': ContentType.objects.get_for_model(Post).id,
                'root_object_id': post.id,
                'next_page': reverse('post', args=[post.slug, post.id])
            })
    else:
        comment_form = None
    return render(request, 'post/view.html', {
        'post': post,
        'comments': comments,
        'comment_form': comment_form
    })
コード例 #2
0
ファイル: comment_block.py プロジェクト: 31029/BlogOfMine
def comment_block(target, user):
    return {
        'user': user,
        'target': target,
        'comment_form': CommentForm,
        'comment_list': Comment.get_comments(target),
    }
コード例 #3
0
ファイル: views.py プロジェクト: KadirCubukcu/DjangoBlog
def post_view(request, post_slug, post_id):
    post = Post.get(post_id)
    if not post:
        raise Http404('The post could not be found')

    if post.status != 'PUBLISHED' and post.user_id != request.user.id \
            or post.slug != post_slug:
        raise Http404('The post could not be found.')

    comments = Comment.get_comments(post)
    if post.status != 'DRAFT':
        comment_form = request.user.is_authenticated() and\
            AuthorizedCommentForm or AnonymousCommentForm
        comment_form = comment_form(initial={
            'root_ctype_id': ContentType.objects.get_for_model(Post).id,
            'root_object_id': post.id,
            'next_page': reverse('post', args=[post.slug, post.id])})
    else:
        comment_form = None
    return render(request, 'post/view.html', {'post': post,
                                              'comments': comments,
                                              'comment_form': comment_form})