def saveComment( request ): email = request.POST['email'] usrname = request.POST['usrname'] content = request.POST['content'] article = Article.objects.get(id = request.POST['aId']) kwarg = {'user' : util.get_or_create_usr(email, usrname),'content' : content} desc = request.POST.get('memo', None) if desc : kwarg['desc'] = desc rootId = request.POST.get('rootId', None) if rootId : kwarg['root_komment'] = Comment.objects.get(id = rootId) kommentId = request.POST.get('cId', None) if content.strip().count('#-') is 1 and kommentId: pattern = re.compile('(#-).*(-#\s*)') content = pattern.sub('', content) komment = Comment.objects.get(id = kommentId) kwarg['content'] = content kwarg['komment'] = komment else: kwarg['article'] = article comment = Comment(**kwarg) comment.save() resp = HttpResponseRedirect('/article/feeds?aId='+str(article.id)+'#comment-'+str(comment.id)) ## if not request.COOKIES.has_key('email') or not request.COOKIES.has_key('usrname'): resp.set_cookie('email', value = email, max_age = 31536000, httponly = True) resp.set_cookie('usrname', value = usrname.encode('utf-8'), max_age = 31536000, httponly = True) return resp
def addComment(request, pk=None): if pk is None or request.method == 'GET': return redirect('/') art = Article.objects.get(pk=pk) comment = request.POST.get('comment') com = Comment(comment=comment, author=request.user, article=art) com.save() return redirect('kb', pk=pk)
def add_comment(request,uuid): # grab the reader comment and save it comment_input = request.POST.get('comment_input') if comment_input: comment = Comment(article_uuid=uuid,comment_text=comment_input) comment.save() # after saving redirect back to the article itself, so that comment can be displayed return HttpResponseRedirect(reverse('article', args=(uuid,)))
def addComment(request, id): article = get_object_or_404(Article, id=id) if request.method == "POST": comment_author = request.POST.get("comment_author") comment_content = request.POST.get("comment_content") newComment = Comment(comment_author=comment_author, comment_content=comment_content) newComment.article = article newComment.save() return redirect(reverse("article:detail", kwargs={"id": id}))
def addComment(request, id): article = get_object_or_404(Article, id=id) if request.method == "POST": comment_author = request.POST.get("comment_author") comment_content = request.POST.get("comment_content") newComment = Comment(comment_author=comment_author, comment_content=comment_content) newComment.article = article newComment.save() messages.success(request, "Yorumunuz Başarıyla Eklendi") return redirect(reverse("article:article", kwargs={"id": id}))
def addComment(request, id): article = get_object_or_404(Article, id=id) if request.method == "POST": comment_author = request.POST.get("comment_author") comment_content = request.POST.get("comment_content") newComment = Comment(comment_author=comment_author, comment_content=comment_content) newComment.article = article newComment.save() return redirect( reverse("article:detail", kwargs={'id': id}) ) # redirect yaparken parametreli url'lere bu şekilde yönlendirme yapılabilir
def addComment(request,id): article = get_object_or_404(Article, id = id) if request.method == "POST": comment_author = request.POST.get("comment_author") comment_content = request.POST.get("comment_content") newComment = Comment(comment_author = comment_author, comment_content = comment_content) newComment.article = article newComment.save() messages.success(request,"Comment successfully added.") return redirect(reverse("article:detail",kwargs={"id":id})) #/articles/article/" + str(id)
def save_comment(request,articleID): error_msg = '' commentID = request.POST.get('commentID', '').strip() save_type = request.POST.get('type', '').strip() # save or submit col = request.POST.get('col', '').strip() content = request.POST.get('content', '').strip() articleID=int(articleID) if content == '': error_msg = u'万言万当,不如一默,真的猛士,敢在沉默中灭亡' if error_msg: return HttpResponse(json.dumps({'status': 'fail', 'error_msg': error_msg})) try: col = Col.objects.get(name=col) except Exception as e: error_msg = str(e) return HttpResponse(json.dumps({'status': 'fail', 'error_msg': error_msg})) if commentID: try: author = Author.objects.get(email=request.user.email) comment = Comment.objects.get(id=commentID) comment.content = content comment.col = col comment.save() except Exception as e: error_msg = str(e) else: try: author = Author.objects.get(email=request.user.email) article=Article.objects.get(id=articleID) comment = Comment( author=author, col=col, content=content,article=article) comment.save() if article.num_comment is None: article.num_comment=1 else: article.num_comment+=1 article.save() except Exception as e: error_msg = str(e) if error_msg: return HttpResponse(json.dumps({'status': 'fail', 'error_msg': error_msg})) commentID = comment.id return HttpResponse(json.dumps({'status': 'ok', 'articleID':articleID,'commentID': commentID, 'error_msg': error_msg}))
def comment_topic(request): if request.GET.get('token') != my_token: return Http404 _user_id = request.GET.get('user_id') _topic_id = request.GET.get('topic_id') _content = request.GET.get('content') if Comment.objects.filter(in_topic_id=_topic_id).count() == 0: _order = 1 else: _order = Comment.objects.filter(in_topic_id=_topic_id).aggregate( Max('order'))['order__max'] + 1 _comment = Comment(commenter_id=_user_id, in_topic_id=_topic_id, content=_content, order=_order) _comment.save() return a_views.get_topic_detail_data(request, msg='评论成功')
def comment(request, id): article = get_object_or_404( Article, id=id ) # dinamik url sayesinde yorum eklenen article'ın idsini alıp kontrol ediyoruz if request.method == "POST": comment_author = request.POST.get("comment_author") comment_content = request.POST.get("comment_content") newComment = Comment(article=article, comment_author=comment_author, comment_content=comment_content) newComment.save() # Veritabanında Comment tablosuna verileri ekliyoruz #return redirect("/articles/article/"+str(id)) return redirect(reverse("article:detail", kwargs={"id": id}))
def post_comment(): aid = int(request.form.get('aid', 0)) content = request.form.get('content', '').strip() uid = session['uid'] created = datetime.datetime.now() comment = Comment(uid=uid, aid=aid, content=content, created=created) db.session.add(comment) db.session.commit() return redirect(f'/article/read?aid={aid}')
def push_comment(): '''发表评论''' uid = session['id'] wid = request.form.get('wid') content = request.form.get('content') now = datetime.datetime.now() comment = Comment(uid=uid, wid=wid, content=content, created=now) db.session.add(comment) db.session.commit() return redirect(f'/article/read?wid={wid}')
def reply(): '''回复评论''' uid = session['id'] wid = request.form.get('wid') cid = request.form.get('cid') # 这里为啥会有 cid 因为我们是对别人的评论进行了回复,所以才会有啊,那通过这个 cid 是不是也可以找到 这条评论的作者呀 content = request.form.get('content') now = datetime.datetime.now() comment = Comment(uid=uid, wid=wid, cid=cid, content=content, created=now) db.session.add(comment) db.session.commit() return redirect(f'/article/read?wid={wid}')
def reply(): aid = int(request.form.get('aid')) cid = int(request.form.get('cid')) content = request.form.get('content') now = datetime.datetime.now() comment = Comment(uid=session['uid'], aid=aid, cid=cid, content=content, created=now) db.session.add(comment) db.session.commit() return redirect((f'/article/read?aid={aid}'))
def comment_art(): if request.method == 'POST': uid = session.get('uid') cid = int(request.form.get('cid', '0')) wid = request.form.get('art_id') content = request.form.get('content') now = datetime.datetime.now() if content: comment = Comment(wid=wid, uid=uid, content=content, create_time=now, cid=cid) db.session.add(comment) db.session.commit() return redirect(f'/article/show?art_id={wid}') else: return redirect(f'/article/show?art_id={wid}&err=评论内容不能为空') else: abort(403)
def recomment(request): if request.method == 'POST': this_post = request.POST aid = this_post.get('aid') # 文章id pid = this_post.get('pid') # 评论id at_name = this_post.get('at_name') # @的人名 message = this_post.get('message') co = Comment() users = User.objects.filter(Q(nickname=at_name) | Q(username=at_name)) if users: co.at_id = users[0].id at_href = reverse('member:index', args=(co.at_id, )) message = '<span class="author-content">回复 <a href="{0}" target="_blank">@{1}</a> :{2}</span>'.format( at_href, at_name, message) co.article_id = aid co.parent_id = pid co.content = this_post.get('message') co.creator_id = request.user.id co.save() return JsonResponse({'result': 1, 'reppid': co.id, 'message': message})
def populate(): print('Populating Article and Comment ... ', end='') Article.objects.all().delete() Comment.objects.all().delete() articles = [] admin = User.objects.get(is_superuser=True) for title in titles: article = Article() article.title = title for j in range(20): article.content += title + '\n' articles.append(article) articles = Article.objects.bulk_create(articles) for article in articles: commentList = [] for comment in comments: commentList.append( Comment(article=article, user=admin, content=comment)) Comment.objects.bulk_create(commentList) print('done')