Exemplo n.º 1
0
def renderPaggedPosts(pageid,pageTitle,pagedPosts,showRecent = False,request=None):   
    #no post return only title
    if pagedPosts.count <=0:
        return render_to_response(LIST_TEMPLATE,
                                  {'pagetitle':pageTitle},
                                  context_instance=RequestContext(request))
    currentPage = pagedPosts.page(pageid)
    data = {'pagetitle':pageTitle,'posts':currentPage.object_list}
    if currentPage.has_next():
        data["next_page"] = pageid +1
    if currentPage.has_previous():
        data["prev_page"] = pageid -1
    if showRecent:
        data["show_recent"] = showRecent    
    context = None
    if request:
        context = RequestContext(request)
    return render_to_response(LIST_TEMPLATE,
                              data,
                              context_instance=context
                              ) 
Exemplo 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)
                                  )        
Exemplo n.º 3
0
                    #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)
                                  )       
    else:
        raise Http404()

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