Ejemplo n.º 1
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!')})            
Ejemplo n.º 2
0
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)
                                  )        
Ejemplo n.º 3
0
     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',
                           {'post':post,'form':form,'msg':msg,'error':error},
                           context_instance=RequestContext(request)