Ejemplo n.º 1
0
def detail_comment(request, page_num):
    form = CommentForm(request.POST)
    if form.is_valid():
        name = form.cleaned_data['name']
        comment = form.cleaned_data['comment']
        article = Aritcle.objects.get(id=page_num)
        c = Comment(name=name, comment=comment, belong_to=article)
        c.save()
        return redirect(to='detail', page_num=page_num)
    else:
        return detail(request, page_num, error_form=form)
Ejemplo n.º 2
0
def comment(request, id):
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data["name"]
            comment = form.cleaned_data["comment"]
            article = Article.objects.get(id=id)
            c = Comment(name=name, comment=comment, belong_to=article)
            c.save()
            return redirect(to="detail", id=id)
    return redirect(to="detail", id=id)
Ejemplo n.º 3
0
def comment(request, id):
    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            comment = form.cleaned_data["comment"]
            c = Comment(comment=comment, belong_to_id=id, commenter_id=request.user.id)
            c.save()
            return redirect(to="detail", id=id)
        else:
            return detail(request, id, error_form=form)
    return redirect(to="detail", id=id)
Ejemplo n.º 4
0
def comment(request, id):
    form = CommentForm(request.POST)
    if form.is_valid():
        comment = form.cleaned_data["comment"]
        article = Article.objects.get(id=id)
        c = Comment(comment=comment,
                    belong_to_article=article,
                    belong_to_user=request.user)
        c.save()
    else:
        return detail(request, id, error_form=form)
    return redirect(to="detail", id=id)
Ejemplo n.º 5
0
def detail_comment(request, page_num):
    form = CommentForm(request.POST)
    if form.is_valid():
        name = form.cleaned_data['name']
        content = form.cleaned_data["content"]
        a = Article.objects.get(id=page_num)
        c = Comment(name=name, content=content, belong_to=a)
        c.save()
    else:
        return detail(request, page_num, error_form=form)

    return redirect(to=detail, id=page_num)
Ejemplo n.º 6
0
def detail_comment(request, page_num):
    # 判断是否登录
    if request.user.is_authenticated:
        # 表单绑定
        form = CommentForm(request.POST)
        # 验证表单
        if form.is_valid():
            content = form.cleaned_data['comment']
            publisher = request.user
            belong_to = Article.objects.get(id=page_num)

            comment = Comment_New(publisher=publisher,
                                  content=content,
                                  belong_to=belong_to)
            comment.save()
            return redirect('detail', page_num)
        else:
            return detail(request, page_num=page_num, error_form=form)
Ejemplo n.º 7
0
def detail(request):

    if request.method == "GET":
        form = CommentForm

    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data["name"]
            content = form.cleaned_data["content"]
            c = Comment(name=name, content=content)
            c.save()
            return redirect(to="detail")

    context = {}
    comment_list = Comment.objects.all()
    context['comment_list'] = comment_list
    context['form'] = form
    return render(request, 'detail.html', context)
Ejemplo n.º 8
0
def detail(request):
    context = {}
    if request.method == "GET":
        # 如果是get,则进行表单的创建,这个时候是未绑定表单
        form = CommentForm
    elif request.method == "POST":
        # 绑定表单,只有当表单绑定的时候才能进行数据检验
        form = CommentForm(request.POST)
        # 校验表单数据,符合规则返回True,否则False
        if form.is_valid():
            name = form.cleaned_data['name']
            comment = form.cleaned_data['comment']
            c = Comment(name=name, comment=comment)
            c.save()
            return redirect(to='detail')

    comment_list = Comment.objects.all()
    context['form'] = form
    context['comment_list'] = comment_list
    return render(request, 'article_detail.html', context)
Ejemplo n.º 9
0
def detail(request, id):
    article = Article.objects.get(id=id)

    if request.method == "GET":
        form = CommentForm

    if request.method == "POST":
        form = CommentForm(request.POST)
        if form.is_valid():
            name = form.cleaned_data["name"]
            comment = form.cleaned_data["comment"]

            c = Comment(name=name, comment=comment, belong_to=article)
            c.save()
            return redirect(to="detail", id=id)

    context = {}
    context["article"] = article
    context['form'] = form

    return render(request, 'detail.html', context)
Ejemplo n.º 10
0
def add_comment_to_post(request,pk):
	post = get_object_or_404(Post,pk=pk)
	if request.method == 'POST':
		form = CommentForm(request.POST)
		if form.is_valid():
			comment = form.save(commit = False)
			comment.post = post
			comment.save()
			return redirect('post_detail',pk=post.pk)
	else:
		form = CommentForm()
	return render(request,'firstapp/comment_form.html',{'form':form})
Ejemplo n.º 11
0
def detail(request, page_num, error_form=None):

    context = {}

    if error_form == None:
        form = CommentForm()

    if error_form:
        form = error_form

    article = Article.objects.get(id=page_num)
    # 更新文章浏览量
    article.views = article.views + 1
    article.save()
    context['view_count'] = article.views
    # 获取关联这篇文章的所有评论
    comments = Comment_New.objects.filter(belong_to_id=article.id)

    # 处理投票业务的数据渲染
    all_ticket_count = article.tickers.count()
    ticket_like_count = article.tickers.filter(vote='like').count()
    ticket_dislike_count = article.tickers.filter(vote='dislike').count()
    context['all_ticket_count'] = all_ticket_count
    context['ticket_like_count'] = ticket_like_count
    context['ticket_dislike_count'] = ticket_dislike_count

    if request.user.is_authenticated:
        user_vote_ticket_like = article.tickers.filter(
            voter_id=request.user.id, vote='like').count()
        user_vote_ticket_dislike = article.tickers.filter(
            voter_id=request.user.id, vote='dislike').count()
        context['user_vote_ticket_like'] = user_vote_ticket_like
        context['user_vote_ticket_dislike'] = user_vote_ticket_dislike

    context['article'] = article
    context['form'] = form
    context['comments'] = comments
    return render(request, 'detail.html', context)