def topic(req,aid): if req.method == 'POST': # 文章评论 comt = req.POST.get('comment','') c = comment(comt=comt) c.art = article(id=aid) c.save() return HttpResponseRedirect('/topic/%s' % aid) # 显示文章 art = article.objects.get(id=aid) comments = art.comments.all() # 反向查询这个文章下的所有评论内容 return render(req,'topic.html',{'art':art,'comments':comments})
def commenting(request): if request.method == 'POST': comm = request.POST.get("comment") cmnt = comment.objects.filter(post = post_title) #import pdb; pdb.set_trace() if not comm == "": obj = comment(user = request.user, post = post_title, text = comm) obj.save() post_title.number_comments += 1 post_title.save() ctx = {'num_comm':post_title.number_comments , 'usr':unicode(request.user), 'tex':unicode(comm) , 'date':obj.date_created.strftime('%b %d, %Y ')} return HttpResponse(json.dumps(ctx), content_type='application/json')
def post(self, request, *args, **kwargs): comment = blog_models.comment() comment.message = request.POST.get("add_comment") pk = request.POST.get("pk") post_to_save = get_object_or_404(blog_models.post, pk=pk) comment.post_id = post_to_save user_to_save = self.request.user comment.user_id = user_to_save comment.save() return redirect('blog:post', pk)
def add_comment(request,id): p = request.POST if p.has_key("body") and p["body"]: if p["author"]: author = p["author"] cmnt = comment(post = blog.objects.get(uid = id)) cf = CommentForm(p, instance = cmnt) cf.fields["author"].required = False comnt = cf.save(commit = False) comnt.author = author comnt.save() arg1=(blog.objects.get(uid = id)).slug return HttpResponseRedirect(reverse("blog.views.view_post",args = [arg1]))
def commenting(request): if request.method == 'POST': comm = request.POST.get("comment") cmnt = comment.objects.filter(post=post_title) #import pdb; pdb.set_trace() if not comm == "": obj = comment(user=request.user, post=post_title, text=comm) obj.save() post_title.number_comments += 1 post_title.save() ctx = { 'num_comm': post_title.number_comments, 'usr': unicode(request.user), 'tex': unicode(comm), 'date': obj.date_created.strftime('%b %d, %Y ') } return HttpResponse(json.dumps(ctx), content_type='application/json')
def addComment(ownerName, comment, articleId): back = {} back['pass'] = False back['str'] = "" try: datetime = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time())) newComment = blog_models.comment(owner=ownerName, comment=comment, article=articleId, date=datetime) newComment.save() back['str'] = u"成功" back['pass'] = True except: back['str'] = u"失败,发生未知错误" return back
def complaint_comment(request): head = tool.getOnlineUser(request) post_id = request.GET.get('post_id') content = request.GET.get('send_content') user = models.user.objects.get(id=head['user_id']) comment = models.comment( content=content, user_id=user, complaint_id=models.complaint.objects.get(id=post_id)) comment.save() complaint = models.complaint.objects.get(id=post_id) complaint.reply_amount += 1 if complaint.status == 0: if user.type == tool.JURY_USER: complaint.status = 2 elif user.type == tool.COMPANY_USER: complaint.status = 3 else: complaint.status = 1 complaint.save() return HttpResponseRedirect('post_detail?post_id=' + post_id)