예제 #1
0
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
예제 #2
0
파일: views.py 프로젝트: minsoopark/blog
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)
예제 #3
0
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!')})            
예제 #4
0
파일: views.py 프로젝트: imtherealk/Blog
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)
예제 #5
0
파일: views.py 프로젝트: bh3kks/pythonWeb
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.')
예제 #6
0
파일: views.py 프로젝트: Fe-ver/myblog-1
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)
예제 #7
0
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')
예제 #8
0
파일: views.py 프로젝트: rangshu/Foodmap
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("문제가 생겨 저장하지 못했습니다.")
예제 #9
0
파일: views.py 프로젝트: 002jnm/Pylogs
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)
                                  )        
예제 #10
0
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,)))
예제 #11
0
파일: views.py 프로젝트: ogonbat/blogbastik
 def post(self, request, slug,*arg, **kwargs ):
     
     context = self.get_context_data(slug, **kwargs)
     
     form = CommentAddForm(request.POST)
     if form.is_valid():
         #add a new comment post
         posts = Posts.all().filter("is_active =", True).filter("slug =", slug).get()
         comment = Comments(title=form.cleaned_data['title'], body=form.cleaned_data['body'], post=posts)
         if form.cleaned_data['answer']:
             comment.answer = Comments.get_by_id(int(form.cleaned_data['answer']))
         if request.user:
             comment.author = request.user
         comment.put()
         return redirect('blog:post', slug=slug)
     
     context['form'] = form
     return self.render_to_response(context)
예제 #12
0
파일: views.py 프로젝트: 002jnm/Pylogs
         post = get_object_or_404(Post,post_name__iexact=postname,post_type__iexact='post')            
 elif int(postid)>0:
     #get by postid
     post = get_object_or_404(Post,id__exact=postid,post_type__iexact='post')
 if post:
     #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
예제 #13
0
파일: views.py 프로젝트: evilbinary/myblog
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)
예제 #14
0
def post_comment():
    comment = Comments(sender=current_user.id, post_id=request.form['post_id'], content=request.form['comment'])
    if request.form['comment']:
        db.session.add(comment)
        db.session.commit()
        return redirect(url_for('blog'))
예제 #15
0
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"
예제 #16
0
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"
예제 #17
0
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)
예제 #18
0
파일: data.py 프로젝트: winkidney/GG-Blog
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()