#!/usr/bin/env Python
# coding=utf-8

from django import template
from passage.models import Category, Sidebar, Post

register = template.Library()


# 所有分类
@register.simple_tag
def get_category_list():
    return Category.objects.all()


# 两侧目录
@register.simple_tag
def get_sidebar_list():
    return Sidebar.get_sidebar()


# 最新文章
@register.simple_tag
def get_new_post():
    return Post.objects.order_by('-pub_date')[:8]


# 热门文章
@register.simple_tag
def get_hot_post():
    return Post.objects.filter(is_hot=True)[:8]


# 热门推荐
@register.simple_tag
def get_hot_pv_post():
    return Post.objects.order_by('-pv')[:8]


# 文章归档
@register.simple_tag
def get_archives():
    return Post.objects.dates('add_date', 'mouth', order='DESC')[:8]
