def comment(request): if request.method == 'POST': #new_comm = CommForm(request.POST) comments = request.POST['newcomments'] if not comments.strip() == "": pid = request.POST['pid'] #pid = -1 timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) mid = request.POST['mid'] # if request.META.has_key('HTTP_X_FORWARDED_FOR'): # ip = request.META['HTTP_X_FORWARDED_FOR'] # else: # ip = request.META['REMOTE_ADDR'] ip = getIPFromDJangoRequest(request) iplocation = getIPLocationFromsite(ip) t = Mail.objects.get(id=mid) t.comment_num = t.comment_num + 1 t.save() floor = t.comment_num p = Comments(pid=pid, timestamp=timestamp, user_ip=ip, user_content=comments, comments_id=mid, user_location=iplocation, floor=floor) p.save() return render_to_response('blog/savedone.html', {'mid': mid}) else: mid = request.POST['mid'] return render_to_response('blog/savefalse.html', {'mid': mid}) else: pass
def blog_detail(request, pk): post = Post.objects.get(pk=pk) posts = Post.objects.all().order_by('-created_on') #comments form = CommentsForm() if request.method == 'POST': form = CommentsForm(request.POST) if form.is_valid(): comment = Comments(author=form.cleaned_data["author"], body=form.cleaned_data["body"], post=post) comment.save() return redirect('blog_index') comments = Comments.objects.filter(post=post) context = { "post": post, "list": posts[:3], "comments": comments, "form": form } return render(request, "blog_detail.html", context)
def post_comment(request,postid): if not request.is_ajax(): raise Http404 vcode = request.POST.get('vcode') if vcode.lower() != request.session.get('vcode'): error = _('The confirmation code you entered was incorrect!') return json({'success':False,'error':error}) else: #set a random string to session, refresh post failed request.session['vcode'] = random.random(); author = request.POST.get('author') email = request.POST.get('email') content = request.POST.get('content') url = request.POST.get('url','') post = Post.objects.get(id__exact=int(postid)) if post.comment_status == models.POST_COMMENT_STATUS[3][0]: # comment no need approve comment_approved_status = models.COMMENT_APPROVE_STATUS[1][0] # comment approved else: comment_approved_status = models.COMMENT_APPROVE_STATUS[0][0] # comment unapproved comment = Comments(post = post, comment_author= author, comment_author_email=email, comment_author_url=url, comment_author_IP= user_host_address(request), comment_content = content, comment_approved=comment_approved_status, comment_agent=request.META['HTTP_USER_AGENT']) comment.save() new_comment_mail(post.title,comment.comment_content) return json({'success':_('Comment post successful!')})
def post(request, id): if request.method == 'GET': # 获取文章内容 post = Post.objects.filter(id=id).first() comment_form = CommentsForm() # 添加阅读数 post.page_view += 1 post.save() context = {'post': post, 'comment_form': comment_form} return render(request, 'blog/post.html', context) elif request.method == 'POST': comment_form = CommentsForm(request.POST) print(comment_form) if comment_form.is_valid(): comm = request.POST['comment'] id = int(request.POST['id']) post = Post.objects.get(id=id) # user = BlogUser.objects.get(id=1) obj = Comments(post=post, content=comm) try: obj.save() except: return HttpResponse('error') return HttpResponseRedirect('/blog/post/' + str(id)) else: id = int(request.POST['id']) post = Post.objects.filter(id=id).first() comment_form = CommentsForm() context = {'post': post, 'comment_form': comment_form} return render(request, 'blog/post.html', context) else: pass
def blog_detail(request, pkey): post = Post.objects.get(pk=pkey) form = CommentForm() success_msg = "" if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): comment = Comments( author=form.cleaned_data['author'], body=form.cleaned_data['body'], post=post ) comment.save() success_msg = "Successfully Submitted! :)" form = CommentForm() else: success_msg = "Failed to submit. :(" comments = Comments.objects.filter(post=post) contxt = {'title': post.title, 'post': post, 'comments': comments, 'form': form, 'success_msg': success_msg} return render(request, 'blog_detail.html', contxt)
def comment(request): if request.method == 'POST': #new_comm = CommForm(request.POST) comments = request.POST['newcomments'] if not comments.strip() == "": pid = request.POST['pid'] #pid = -1 timestamp = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()) mid = request.POST['mid'] # if request.META.has_key('HTTP_X_FORWARDED_FOR'): # ip = request.META['HTTP_X_FORWARDED_FOR'] # else: # ip = request.META['REMOTE_ADDR'] ip = getIPFromDJangoRequest(request) iplocation = getIPLocationFromsite(ip) t = Mail.objects.get(id = mid) t.comment_num = t.comment_num + 1 t.save() floor = t.comment_num p = Comments(pid=pid,timestamp=timestamp,user_ip=ip,user_content=comments,comments_id=mid,user_location=iplocation,floor=floor) p.save() return render_to_response('blog/savedone.html',{'mid':mid}) else: mid = request.POST['mid'] return render_to_response('blog/savefalse.html',{'mid':mid}) else: pass
def add_comment(request): cmt_name = request.POST.get('name', '') if not cmt_name.strip(): return HttpResponse('작성자 이름이 올바르지 않습니다.') cmt_content = request.POST.get('content', '') if not cmt_content.strip(): return HttpResponse('댓글 내용을 입력하세요.') if request.POST.has_key('entry_id') == False: return HttpResponse('댓글 달 글이 지정되어있지 않습니다.') else: try: entry = Entries.objects.get(id=request.POST['entry_id']) except: return HttpResponse('없는 글입니다.') new_cmt = Comments(Name=cmt_name, Content=cmt_content, Entry=entry) try: new_cmt.save() except: return HttpResponse('제대로 저장하지 못했습니다.') entry.Comments += 1 entry.save() return HttpResponse('%s번 글에 댓글을 달았습니다.' % entry.id)
def post_detail_view(request, year, month, day, post): post1 = Post.objects.get(title=post, status='published', publish__year=year) #publish__month=month) # publish__day=day) commentss = post1.commentss.filter(active=True) csubmit = False current_user = request.user if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): name = current_user.username email = current_user.email comment = request.POST.get('comment') data = Comments(name=name, email=email, comment=comment) data.post = post1 data.save() csubmit = True else: form = CommentForm() return render( request, 'blog/post_detail.html', { 'post2': post1, 'sidebar': True, 'comments': commentss, 'form': form, 'csubmit': csubmit })
def add_comment(request): name = request.POST.get('name', '') if name == '': return HttpResponse("이름 입력하세요") pwd = request.POST.get('password', '') if pwd == '': return HttpResponse("비밀번호 입력하세요") pwd = hashlib.md5(pwd.encode('utf-8')).hexdigest() content = request.POST.get("content", '') if content == '': return HttpResponse("내용 입력하세요") entry_id = request.POST.get('entry_id', '') if entry_id == '': return HttpResponse("댓글 달 글을 지정해야 합니다.") entry = Entries.objects.get(id=entry_id) new_cmt = Comments(name=name, password=pwd, content=content, entry=entry) new_cmt.save() comments = Comments.objects.filter(entry=entry).order_by('created') entry.comment_num = len(comments) entry.save() if request.is_ajax(): return_data = { 'entry_id': entry.id, 'msg': get_comments(request, entry.id, True) } return HttpResponse(json.dumps(return_data)) else: return redirect('blog.views.read', entry_id=entry.id)
def comment(request, slug): if request.method == "POST": form = (request.POST) id = Articles.objects.get(slug=slug).id comment = Comments(comments=form['comment'], article_id=id) comment.save() messages.info(request, "Your comment has been successfully added") prev = request.POST.get('prev', '/') return (HttpResponseRedirect(prev))
def post(self, request, *args, **kwargs): new_comment = Comments( Comment=request.POST.get('Comment'), author=self.request.user, post_connected=self.get_object(), ) new_comment.save() # return self.get(self, request, *args, **kwargs)
def make_comment(comment_form): new_comment = Comments() new_comment.author = comment_form.cleaned_data['fusername'] new_comment.author_email = comment_form.cleaned_data['femail'] new_comment.author_url = comment_form.cleaned_data['fwebsite'] new_comment.content = comment_form.cleaned_data['fmessage'] new_comment.post_id = 0 new_comment.parent_id = 0 new_comment.user_id = 0 new_comment.author_ip = '192.168.1.1' new_comment.save()
def addComment(request, article_id): if request.POST['comment'] != "": article = get_object_or_404(Article, pk=article_id) comment = Comments() comment.article = article if request.POST['name'] != "": comment.name = request.POST['name'] else: comment.name = 'Unknown' comment.comment = request.POST['comment'] comment.date = timezone.now() comment.save() return HttpResponseRedirect(reverse('detail', args=(article.id,)))
def submitComment(request, blog_id): blog = Blog.objects.get(pk=blog_id) blog.num_of_comments += 1 comment = Comments() comment.blog = blog comment.commenter = request.POST['commenter'] comment.email = request.POST['email'] comment.content = request.POST['content'] comment.posted = request.POST['posted'] comment.save() blog.save() return HttpResponseRedirect(reverse('entry', args=(blog.id, )))
def add_comment(request): # 이름 검사 if 'name' in request.POST: if len(request.POST['name']) == 0: return HttpResponse('이름을 입력하세요.') else: cmt_name = request.POST['name'] else: return HttpResponse('False in name') # 비밀번호 검사 if 'password' in request.POST: if len(request.POST['password']) == 0: return HttpResponse('비밀번호를 입력하세요.') else: cmt_password = request.POST['password'] else: return HttpResponse('False in password') # 내용 검사 if 'content' in request.POST: if len(request.POST['content']) == 0: return HttpResponse('내용을 입력하세요.') else: cmt_content = request.POST['content'] else: return HttpResponse('False in content') # 댓글을 달 글 확인 if 'entry_id' in request.POST: try: entry = Entries.objects.get(id=request.POST['entry_id']) except: return HttpResponse('그런 글은 없지롱') else: return HttpResponse('False in entry_id') try: new_cmt = Comments(Name=cmt_name, Password=cmt_password, Content=cmt_content, Entry=entry) new_cmt.save() entry.Comments += 1 entry.save() return HttpResponse('댓글 입력 완료.') except: return HttpResponse('False.') return HttpResponse('False in final.')
def blog_detail(request, pk): post = Post.objects.get(pk=pk) form = comment_form() if request.method == 'POST': form = comment_form(request.POST) if form.is_valid(): comment = Comments(author=form.cleaned_data["author"], body=form.cleaned_data["body"], post=post) comment.save() comments = Comments.objects.filter(post=post) context = {"post": post, "comments": comments, "form": form} return render(request, "blog_detail.html", context)
def comment(request): if request.method=='POST': form=CommentForm(request.POST) comment_post_id=request.POST.get('comment_post_ID').strip() frequency_comment=request.session['frequency_comment'] if frequency_comment: contexts={'frequency_comment':'评论太频繁了!'} return article(request,comment_post_id,contexts) if form.is_valid(): comment_content=request.POST.get('comment') comment_author=request.POST.get('author').strip() comment_email=request.POST.get('email').strip() comment_url=request.POST.get('url').strip() comment_parent=request.POST.get('comment_parent').strip() comment_author_ip=get_client_ip(request) comment_agent=request.META.get('HTTP_USER_AGENT',None) if comment_post_id==None or comment_parent==None: return index(request) if comment_author=='' or comment_email=='' or comment_content=='': return article(request,comment_post_id) p=Posts.objects.get(pk=comment_post_id) comment=Comments(comment_post=p,comment_approved='0',comment_author=comment_author,comment_parent=comment_parent,comment_content=comment_content,comment_author_email=comment_email,comment_author_url=comment_url,comment_author_ip=comment_author_ip,comment_agent=comment_agent) # comment.comment_date=datetime() p.comment_count=p.comment_count+1 p.save() comment.save() request.session['comment_author']=comment_author request.session['comment_email']=comment_email #context={'test':comment_post_id} if(p.post_type=='post'): #return article(request,comment_post_id) return HttpResponseRedirect('/blog/article/'+comment_post_id+'#comment-%s'%comment.comment_id)#防止重复提交 elif(p.post_type=='page'): #return page(request,comment_post_id) return HttpResponseRedirect('/blog/page/'+comment_post_id)#防止重复提交 else: #t = loader.get_template('test.html') #return HttpResponse(t.render(Context({'form':form})) ) contexts={'comment_form':form} return article(request,comment_post_id,contexts) pass else: pass return index(request)
def add_comment(request): # 글쓴이 이름 처리 if request.POST.has_key("name") == False: return HttpResponse("글쓴이 이름을 입력해야 한다우.") else: if len(request.POST["name"]) == 0: return HttpResponse("글쓴이 이름을 입력해야 한다우.") else: cmt_name = request.POST["name"] # 비밀번호 if request.POST.has_key("password") == False: return HttpResponse("비밀번호를 입력해야 한다우.") else: if len(request.POST["password"]) == 0: return HttpResponse("비밀번호를 입력해야 한다우.") else: cmt_password = md5.md5(request.POST["password"]).hexdigest() # 댓글 본문 처리 if request.POST.has_key("content") == False: return HttpResponse("댓글 내용을 입력해야 한다우.") else: if len(request.POST["content"]) == 0: return HttpResponse("댓글 내용을 입력해야 한다우.") else: cmt_content = request.POST["content"] # 댓글 달 글 확인 if request.POST.has_key("entry_id") == False: return HttpResponse("댓글 달 글을 지정해야 한다우. ") else: try: entry = Entries.objects.get(id=request.POST["entry_id"]) except: return HttpResponse("그런 글은 없지롱") try: new_cmt = Comments(Name=cmt_name, password=cmt_password, Content=cmt_content, Entry=entry) new_cmt.save() entry.Comments += 1 # entry.Comments + 1 entry.save() return redirect("/blog/entry/" + str(e_id)) except: return HttpResponse("제대로 저장하지 못했습니다.") return HttpResponse("문제가 생겨 저장하지 못했습니다.")
def add_comment(request): if request.user == False: return HttpResponse('ㅁㄴㅇㄹ') cmt_password = request.POST.get('password', '') if not cmt_password.strip(): return HttpResponse('fill out password') #cmt_password = md5.md5(cmt_password).hexdigest() cmt_content = request.POST.get('content','') if not cmt_content.strip(): return HttpResponse('fill out commnet') if request.POST.has_key('entry_id') == False: return HttpResponse('select the article') else: try: entry = Entries.objects.get(id=request.POST['entry_id']) except: return HttpResponse('nothing') try: if request.is_ajax: new_cmt = Comments(Name=request.user, Password=cmt_password, Content=cmt_content, Entry=entry) new_cmt.save() entry.Comments += 1 entry.save() return_data = { 'entry_id' : entry.id, 'msg': get_comments(request, entry.id, True), 'user' : request.user, } return HttpResponse(json.dumps(return_data), content_type='application/json') except: return HttpResponse('fail to write1') return HttpResponse('fail to write2')
def blog_detail(request, pk): post = Post.objects.get(pk=pk) form = CommentForm() if request.method == 'POST': form = CommentForm(request.POST) if form.is_valid(): comment = Comments(author=form.cleaned_data['author'], body=form.cleaned_data['body'], post=post) comment.save() form = CommentForm() comments = Comments.objects.filter(post=post) context = { 'form': form, 'post': post, 'comments': comments, } return render(request, 'blogs/blog_detail.html', context)
def page(request,pagename): '''get page by page name''' msg = None error = None if pagename: try: page = get_object_or_404(Post,post_name__exact=pagename,post_type__iexact='page') except Http404,e: pagename = urlquote(pagename) page = get_object_or_404(Post,post_name__exact=pagename,post_type__iexact='page') #post back comment if request.method == 'POST': form = blog_forms.CommentForm(request.POST) if request.POST.get('comment_vcode','').lower() != request.session.get('vcode',''): error = 'The confirmation code you entered was incorrect!' else: if form.is_valid(): comment = Comments(post = page, comment_author=form.cleaned_data['comment_author'], comment_author_email=form.cleaned_data['comment_author_email'], comment_author_url=form.cleaned_data['comment_author_url'], comment_author_IP=request.META['REMOTE_ADDR'], comment_content = form.cleaned_data['comment_content'], comment_approved=str(models.COMMENT_APPROVE_STATUS[0][0]), comment_agent=request.META['HTTP_USER_AGENT']) comment.save() #send mail to admin new_comment_mail(page.title,comment.comment_content) msg = _('Comment post successful!') form = blog_forms.CommentForm() #if allow comment,show the comment form elif page.comment_status == models.POST_COMMENT_STATUS[0][0]: form = blog_forms.CommentForm() else: form = None if not request.session.get('post_hits_%s' % page.id): #update hits count page.hits = page.hits + 1 page.save() request.session['post_hits_%s' % page.id] = True; return render_to_response('wap/page.html', {'post':page,'form':form,'msg':msg,'error':error}, context_instance=RequestContext(request) )
def blog_detail(request, *args, **kwargs): blog = Blog.objects.get(id=id) selected_blog_id = kwargs['productId'] blog: Blog = Blog.objects.get_by_id(selected_blog_id) if blog is None or not blog.active: raise Http404('محصول مورد نظر یافت نشد') blog.visit_count += 1 blog.save() related_blogs = Blog.objects.get_queryset().filter( categories__blog=blog).distinct() grouped_related_blogs = my_grouper(3, related_blogs) comments = Comments.objects.all().filter(blog=blog) if request.user == "POST": form = CommentForm(request.POST) if form.is_valid(): new_name = form.cleaned_data['name'] new_email = form.cleaned_data['email'] new_message = form.cleaned_data['message'] new_Comments = Comments(blog=blog, name=new_name, email=new_email, message=new_message) new_Comments.save() context = { 'blog': blog, "related_blog": grouped_related_blogs, "comments": comments, } tag = Tag.objects.first() return render(request, 'blog_pages/blog_detail.html', context)
def save_comment(request, *args, **kwargs): post_id = request.GET.get('post_id') email = request.GET.get('email') name = request.GET.get('name') entry = request.GET.get('comment') # post = get_object_or_404(Post, pk=post_id) post = Post.objects.get(pk=post_id) comment = Comments(post=post, name=name, email=email, entry=entry) comment.save() response = { 'email': comment.email, 'name': comment.name, 'entry': comment.entry, 'publ_date': comment.get_display_date() } return HttpResponse( json.dumps(response), 'content-type: text/json', **kwargs )
def postComment(request): if request.method == 'POST': comment = request.POST.get('comment') user = request.user postSno = request.POST.get('postSno') post = BlogAppPost.objects.get(sno=postSno) parent = request.POST.get('parent') parentSno = request.POST.get('parentSno') if parentSno == "": comment = Comments(comment=comment, post=post, user=user) messages.success(request, "Your comment has been sent successfully.") else: parent = Comments.objects.get(sno=parentSno) comment = Comments(comment=comment, post=post, user=user, parent=parent) messages.success(request, "Your reply has been sent successfully.") comment.save() # messages.success(request,"Your comment has been sent successfully.") return redirect(f'/blog/{post.slug}')
def blog_detail(request, pk): post = Post.objects.get(pk=pk) logger.debug("start") form = CommentForm() if request.method == "POST": form = CommentForm(request.POST) if form.is_valid(): comment = Comments( author=form.cleaned_data["author"], body=form.cleaned_data["body"], post=post, ) comment.save() else: logger.error("Invalid form") comments = Comments.objects.filter(post=post) context = {"post": post, "comments": comments, "form": form} return render(request, "blog_detail.html", context)
#post back comment if request.method == 'POST': form = blog_forms.CommentForm(request.POST) if request.POST.get('comment_vcode','').lower() != request.session.get('vcode',''): error = _('The confirmation code you entered was incorrect!') else: if form.is_valid(): comment = Comments(post = post, comment_author=form.cleaned_data['comment_author'], comment_author_email=form.cleaned_data['comment_author_email'], comment_author_url=form.cleaned_data['comment_author_url'], comment_author_IP=request.META['REMOTE_ADDR'], comment_content = form.cleaned_data['comment_content'], comment_approved=str(models.COMMENT_APPROVE_STATUS[0][0]), comment_agent=request.META['HTTP_USER_AGENT']) comment.save() #send mail to admin new_comment_mail(post.title,comment.comment_content) msg = _('Comment post successful!') form = blog_forms.CommentForm() #if allow comment,show the comment form elif post.comment_status == models.POST_COMMENT_STATUS[0][0]: form = blog_forms.CommentForm() else: form = None if not request.session.get('post_hits_%s' % post.id): #update hits count post.hits = post.hits + 1 post.save() request.session['post_hits_%s' % post.id] = True; return render_to_response('wap/post.html',
def post_comment(request): try: p = Comments(post_id=request.POST.get('post_id'), comment=request.POST.get('comment_text'), comm_by=request.user) p.save() except Exception, e: print "Error in commenting"
def reply(request): try: p = Comments(post_id=request.POST.get('post_id'), comment=request.POST.get('comment_text'), comm_by=request.user, comment_of_comment_id=request.POST.get('reply_of')) p.save() except Exception, e: print "unable to comment"
def comment(request): if request.method=='POST': data=request.POST if request.user.is_authenticated(): data={} if request.user.user_nicename: data['author']=request.user.user_nicename elif request.user.display_name: data['author']=request.user.display_name elif request.user.user_login: data['author']=request.user.user_login else: data['author']='' data['email']=request.user.user_email data['url']=request.user.user_url data['comment']=request.POST.get('comment').strip() # print 'is is_authenticated',data form=CommentForm(data) comment_post_id=request.POST.get('comment_post_ID').strip() frequency_comment=request.session['frequency_comment'] if request.user.has_perm('blog.can_comment_unlimit_time'): frequency_comment=None if frequency_comment: contexts={'frequency_comment':'评论太频繁了!'} return article(request,comment_post_id,contexts) # print 'comment save3' if form.is_valid(): # print 'comment save2' comment_content=form.cleaned_data['comment'] # print comment_content comment_author=form.cleaned_data['author'] comment_email=form.cleaned_data['email'] comment_url=form.cleaned_data['url'] comment_parent=request.POST.get('comment_parent').strip() print 'comment_parent:',comment_parent comment_author_ip=get_client_ip(request) comment_agent=request.META.get('HTTP_USER_AGENT',None) if comment_post_id==None or comment_parent==None: return index(request) if comment_author=='' or comment_email=='' or comment_content=='': return article(request,comment_post_id) comment_approved=0; if request.user.is_authenticated(): if request.user.has_perm('blog.can_comment_direct'): comment_approved=1 p=Posts.objects.get(pk=comment_post_id) comment=Comments(comment_post=p,comment_approved=comment_approved,comment_author=comment_author,comment_parent=comment_parent,comment_content=comment_content,comment_author_email=comment_email,comment_author_url=comment_url,comment_author_ip=comment_author_ip,comment_agent=comment_agent) # comment.comment_date=datetime() p.comment_count=p.comment_count+1 p.save() comment.save() # print 'comment save' request.session['comment_author']=comment_author request.session['comment_email']=comment_email #context={'test':comment_post_id} if(p.post_type=='post'): #return article(request,comment_post_id) return HttpResponseRedirect('/blog/article/'+comment_post_id+'#comment-%s'%comment.comment_id)#防止重复提交 elif(p.post_type=='page'): #return page(request,comment_post_id) return HttpResponseRedirect('/blog/page/'+comment_post_id)#防止重复提交 else: #t = loader.get_template('test.html') #return HttpResponse(t.render(Context({'form':form})) ) contexts={'comment_form':form} return article(request,comment_post_id,contexts) pass else: pass return index(request)
def comment(request): if request.method=='POST': data=request.POST if request.user.is_authenticated(): data={} if request.user.user_nicename: data['author']=request.user.user_nicename elif request.user.display_name: data['author']=request.user.display_name elif request.user.user_login: data['author']=request.user.user_login else: data['author']='' data['email']=request.user.user_email data['url']=request.user.user_url data['comment']=request.POST.get('comment').strip() # print 'is is_authenticated',data form=CommentForm(data) comment_post_id=request.POST.get('comment_post_ID').strip() frequency_comment=request.session['frequency_comment'] if request.user.has_perm('blog.can_comment_unlimit_time'): frequency_comment=None if frequency_comment: contexts={'frequency_comment':'评论太频繁了!'} return article(request,comment_post_id,contexts) # print 'comment save3' if form.is_valid(): # print 'comment save2' comment_content=form.cleaned_data['comment'] # print comment_content comment_author=form.cleaned_data['author'] comment_email=form.cleaned_data['email'] comment_url=form.cleaned_data['url'] comment_parent=request.POST.get('comment_parent').strip() comment_author_ip=get_client_ip(request) comment_agent=request.META.get('HTTP_USER_AGENT',None) if comment_post_id==None or comment_parent==None: return index(request) if comment_author=='' or comment_email=='' or comment_content=='': return article(request,comment_post_id) comment_approved=0; if request.user.is_authenticated(): if request.user.has_perm('blog.can_comment_direct'): comment_approved=1 p=Posts.objects.get(pk=comment_post_id) comment=Comments(comment_post=p,comment_approved=comment_approved,comment_author=comment_author,comment_parent=comment_parent,comment_content=comment_content,comment_author_email=comment_email,comment_author_url=comment_url,comment_author_ip=comment_author_ip,comment_agent=comment_agent) # comment.comment_date=datetime() p.comment_count=p.comment_count+1 p.save() comment.save() # print 'comment save' request.session['comment_author']=comment_author request.session['comment_email']=comment_email #context={'test':comment_post_id} if(p.post_type=='post'): #return article(request,comment_post_id) return HttpResponseRedirect('/blog/article/'+comment_post_id+'#comment-%s'%comment.comment_id)#防止重复提交 elif(p.post_type=='page'): #return page(request,comment_post_id) return HttpResponseRedirect('/blog/page/'+comment_post_id)#防止重复提交 else: #t = loader.get_template('test.html') #return HttpResponse(t.render(Context({'form':form})) ) contexts={'comment_form':form} return article(request,comment_post_id,contexts) pass else: pass return index(request)