Beispiel #1
0
def renderPaggedPosts(pageid,pageTitle,pagedPosts,showRecent = False,request=None,tab='home'):   
    #no post return only title
    if pagedPosts.count <=0:
        return render_to_response(theme_template_url()+ '/blog/list.html',
                                  {'pagetitle':pageTitle,'tab':tab},
                                  context_instance=RequestContext(request))
    currentPage = pagedPosts.page(pageid)
    data = {'pagetitle':pageTitle,'ol':currentPage,'tab':tab}    
    if request:
        context = RequestContext(request)
    return render_to_response(theme_template_url()+ '/blog/list.html',
                              data,
                              context_instance=context)
Beispiel #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:
            #Backwards compatible handle
            pagename = urlquote(pagename)
            page = get_object_or_404(Post,post_name__exact=pagename,post_type__iexact='page')            
        #post back comment
        if (page.comment_status == models.POST_COMMENT_STATUS[0][0])  or (page.comment_status == models.POST_COMMENT_STATUS[3][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;     
        comments = Paginator(page.comments_set.filter(comment_approved__iexact=
                                                    COMMENT_APPROVE_STATUS[1][0]).order_by('comment_date'),
                                                    PAGE_SIZE
                          )
        pageid = int(request.GET.get('page', 1))
        from templatetags.filters import pageclass
        tab = pageclass(page.id)
        
        return render_to_response(theme_template_url()+ '/blog/page.html',
                                  {'post':page,
                                    'form':form,
                                    'comments':comments.page(pageid),
                                    'msg':msg,
                                    'error':error,
                                    'tab': tab},
                                  context_instance=RequestContext(request))        
Beispiel #3
0
from django.utils.dateformat import format
from blog.templatetags.themes import theme_template_url

register = Library()
def get_tagged_posts(tags,number_of_posts,exclude_id = None):
    '''get tagged related posts'''
    posts = []
    for tag in tags:        
        if len(posts) < number_of_posts:
            for p in tag.post_set.filter(post_type__iexact='post')[:number_of_posts-len(posts)]:
                if (not exclude_id or p.id != exclude_id) and p not in posts:
                    posts.append(p)                   
        else:
            break    
    return {'posts':posts}
register.inclusion_tag(['%s/blog/tags/related_posts.html' % theme_template_url(),
                        'blog/tags/related_posts.html'])(get_tagged_posts)

class archive:
    link = ''
    title = ''
    
def get_archivelist(context):
    '''
    get the month list which have posts
    ''' 
    months = Post.objects.dates('pubdate','month',order='DESC')
    archive_months = []    
    for mon in months:
        m = archive()
        m.link = "/" + format(mon,'Y/m') + "/"
Beispiel #4
0
#coding=utf-8
from django.template import Library

from blog.models import Links
from blog.templatetags.themes import theme_template_url

register = Library()
def get_links(context):  
    links = Links.objects.all()
    return {'links':links}   
register.inclusion_tag(['%s/blog/tags/links.html' % theme_template_url(),
                        'blog/tags/links.html'],
                        takes_context=True)(get_links)
Beispiel #5
0
#coding=utf-8
from django.template import Library
from django.utils.translation import ugettext as _

from blog.models import Post
from blog.templatetags.themes import theme_template_url
register = Library()

def get_menus(context):
    '''
    get the top nav menus
    '''
    pages = Post.objects.filter(post_type__exact='page',post_status__iexact = 'publish').order_by('menu_order')   
    menus = [] 
    if pages:
        for page in pages:           
            menus.append(page)
    return {'menus':menus}    
register.inclusion_tag(['%s/blog/tags/menu.html' % theme_template_url(),
                        'blog/tags/menu.html'],
                        takes_context=True)(get_menus)
Beispiel #6
0
 def render(self, context):
     t = template.loader.select_template([theme_template_url() + '/blog/tags/menu.html',
                                          'blog/tags/menu.html'])
     context['menus'] = self.menus
     return t.render(context)
Beispiel #7
0
        #post back comment
        if (post.comment_status == models.POST_COMMENT_STATUS[0][0]) or (post.comment_status == models.POST_COMMENT_STATUS[3][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;  
        comments = Paginator(post.comments_set.filter(comment_approved__iexact=
                                                            COMMENT_APPROVE_STATUS[1][0]).order_by('comment_date'),
                                                            PAGE_SIZE
                                  )
        pageid = int(request.GET.get('page', 1))  
        return render_to_response(theme_template_url()+ '/blog/post.html',
                                  {'post':post,'form':form,'msg':msg,'error':error,
                                'comments':comments.page(pageid),
                                'tab':'home'},
                                  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:
Beispiel #8
0
#coding=utf-8
from django.template import Library

from blog.models import Links
from blog.templatetags.themes import theme_template_url

register = Library()


def get_links(context):
    links = Links.objects.all()
    return {'links': links}


register.inclusion_tag(
    ['%s/blog/tags/links.html' % theme_template_url(), 'blog/tags/links.html'],
    takes_context=True)(get_links)