#!/usr/bin/env python3
#_*_ coding:utf-8 _*_
#Author:wd
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@register .simple_tag
def filter_all(article_arg,condition):
‘‘‘
处理条件为全部
:param article_arg: 当前url字典:如{‘article_type_id‘: 1, ‘category_id‘: 1}
:param condition: 要处理的条件,如article_type_id,用于区分当前处理选择了那个全部
:return: 返回下面页面形式
{% if article_arg.article_type_id == 0 %}
<a class="active" href="/cmdb/article-0-{{ article_arg.category_id }}.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >全部</a>
{% else %}
<a href="/cmdb/article-0-{{ article_arg.category_id }}.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >全部</a>
{% endif %}
{% for row in article_type %}
{% if row.id == article_arg.article_type_id %}
<a class="active" href="/cmdb/article-{{ row.id }}-{{ article_arg.category_id }}.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ row.caption }}</a>
{% else %}
<a href="/cmdb/article-{{ row.id }}-{{ article_arg.category_id }}.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ row.caption }}</a>
{% endif %}
{% endfor %}
‘‘‘
if condition = = ‘article_type_id‘ :
if article_arg[condition] = = 0 :
print (article_arg[ ‘category_id‘ ])
res = ‘<a class ="active" href="/cmdb/article-0-%s.html" rel="external nofollow" rel="external nofollow" >全部</a>‘ % article_arg[ ‘category_id‘ ]
else :
res = ‘<a href="/cmdb/article-0-%s.html" rel="external nofollow" rel="external nofollow" >全部</a>‘ % article_arg[ ‘category_id‘ ]
return mark_safe(res)
elif condition = = ‘category_id‘ :
if article_arg[ ‘category_id‘ ] = = 0 :
res = ‘<a class ="active" href="/cmdb/article-%s-0.html" rel="external nofollow" rel="external nofollow" >全部</a>‘ % article_arg[ ‘article_type_id‘ ]
else :
res = ‘<a href="/cmdb/article-%s-0.html" rel="external nofollow" rel="external nofollow" >全部</a>‘ % article_arg[ ‘article_type_id‘ ]
return mark_safe(res)
@register .simple_tag
def filter_type(article_type,article_arg):
‘‘‘
:param article_type: article_type对象
:param article_arg: 当前url字典
:return:
{% for row in article_type %}
{% if row.id == article_arg.article_type_id %}
<a class="active" href="/cmdb/article-{{ row.id }}-{{ article_arg.category_id }}.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ row.caption }}</a>
{% else %}
<a href="/cmdb/article-{{ row.id }}-{{ article_arg.category_id }}.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ row.caption }}</a>
{% endif %}
{% endfor %}
‘‘‘
res = []
for row in article_type:
if row. id = = article_arg[ ‘article_type_id‘ ]:
temp = ‘<a class="active" href="/cmdb/article-%s-%s.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >%s</a>‘ % (row. id ,article_arg[ ‘category_id‘ ],row.caption)
else :
temp = ‘<a href="/cmdb/article-%s-%s.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >%s</a>‘ % (row. id , article_arg[ ‘category_id‘ ],row.caption)
res.append(temp)
return mark_safe("".join(res))
@register .simple_tag
def filter_category(article_category,article_arg):
‘‘‘
:param article_type: article_category对象
:param article_arg: 当前url字典
:return:
{% for row in article_category %}
{% if row.id == article_arg.category_id %}
<a class="active" href="/cmdb/article-{{ article_arg.article_type_id }}-{{ row.id }}.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ row.caption }}</a>
{% else %}
<a href="/cmdb/article-{{ article_arg.article_type_id }}-{{ row.id }}.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >{{ row.caption }}</a>
{% endif %}
{% endfor %}
‘‘‘
res = []
for row in article_category:
if row. id = = article_arg[ ‘category_id‘ ]:
temp = ‘<a class="active" href="/cmdb/article-%s-%s.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >%s</a>‘ % (article_arg[ ‘article_type_id‘ ],row. id ,row.caption)
else :
temp = ‘<a href="/cmdb/article-%s-%s.html" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >%s</a>‘ % (article_arg[ ‘article_type_id‘ ],row. id ,row.caption)
res.append(temp)
return mark_safe("".join(res))
|