Created
November 26, 2013 03:41
-
-
Save Nataila/7653140 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% load i18n %} | |
{% load apps_filter %} | |
{% if paged_objects.has_other_pages %} | |
<div class="row-fluid"> | |
<div class="pull-right"> | |
<div class="pagination ks-pagination {{ position_css }}"> | |
<ul> | |
{% if paged_objects.has_previous %} | |
<li><a href="?page={{ paged_objects.previous_page_number }}{% if params_str %}{{ params_str }}{% endif %}">{% trans '上一页' %}</a> | |
{% else %} | |
<li class="disabled"><a href="#">{% trans '上一页' %}</a> | |
{% endif %} | |
{% if paged_objects.number|gt:0 %} | |
<li><a href="?page=1{% if params_str %}{{ params_str }}{% endif %}">1</a> | |
<li class="disabled"><a href="#">...</a> | |
{% endif %} | |
{% for page_index in paged_objects.paginator.page_range|my_page_range:paged_objects.number %} | |
{% ifequal paged_objects.number page_index %} | |
<li class="active"><a href="#">{{ page_index }}</a> | |
{% else %} | |
<li><a href="?page={{ page_index }}{% if params_str %}{{ params_str }}{% endif %}">{{ page_index }}</a> | |
{% endifequal %} | |
{% endfor %} | |
{% if paged_objects.paginator.num_pages|gt:paged_objects.number %} | |
<li class="disabled"><a href="#">...</a> | |
{% endif %} | |
{% if paged_objects.has_next %} | |
<li><a href="?page={{ paged_objects.paginator.num_pages }}{% if params_str %}{{ params_str }}{% endif %}">{{ paged_objects.paginator.num_pages }}</a> | |
<li><a href="?page={{ paged_objects.next_page_number }}{% if params_str %}{{ params_str }}{% endif %}">{% trans '下一页' %}</a> | |
{% else %} | |
<li class="disabled"><a href="#">{% trans '下一页' %}</a> | |
{% endif %} | |
</ul> | |
</div> | |
</div> | |
</div> | |
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding=utf-8 | |
from django import template | |
register = template.Library() | |
# start 分页相关 | |
@register.inclusion_tag('paginator_bootstrap.html') | |
def show_paginator(paged_objects, position_css, params_str=None): | |
'''用于分页的包含页面标签 | |
用法 | |
需要的模板中加入{% show_paginator hosts "page" %} | |
修改 | |
直接修改模板paginator.html | |
''' | |
# TODO 1|2...99|98分页 | |
# TODO 分页显示数量 | |
return {'paged_objects': paged_objects, 'position_css': position_css, 'params_str': params_str} | |
@register.filter | |
def my_page_range(page_range, cur_page_num): | |
start_index = cur_page_num - 1 | |
if page_range[start_index] < 5: | |
if page_range[start_index] == len(page_range): | |
return page_range | |
elif len(page_range) <= 6: | |
return page_range[:-1] | |
else: | |
return page_range[:6] | |
elif page_range[start_index] > len(page_range) - 5: | |
if page_range[start_index] == len(page_range): | |
return page_range[-6:] | |
elif page_range[start_index] in page_range[-6:-4] : | |
return page_range[cur_page_num - 3:cur_page_num + 3] | |
elif page_range[start_index] == 5: | |
return page_range[cur_page_num - 3:cur_page_num + 1] | |
else: | |
return page_range[-6:-1] | |
elif 6 < page_range[start_index] < len(page_range): | |
page_range = page_range[:-1] | |
return page_range[cur_page_num - 3:cur_page_num + 3] | |
else: | |
return page_range[cur_page_num - 3:cur_page_num + 3] | |
@register.filter | |
def gt(a, b): | |
return a > b + 4 or b < 6 and a >= 6 | |
# end 分页相关 | |
@register.filter | |
def is_menu(cur_path, menu): | |
if cur_path: | |
return menu[:-1] in cur_path # /example/list 和 /example/list/ 认为是一个 | |
else: | |
return False | |
@register.filter | |
def mongo_id(value): | |
return value.get('_id') if value else None | |
@register.filter | |
def get_comma_str_item(comma_str, show_type): | |
'''拆分用逗号分割的字符串,如果show_type为"all"则显示所有,其他只返回第一个 | |
列表中节省空间,只显示一个CVE-ID,详细页面显示所有的 | |
BUG_ID, OSWAP_LEVEL同 | |
''' | |
if comma_str: | |
ids = [item.strip() for item in comma_str.split(',')] | |
if show_type == 'all': | |
return ids | |
else: | |
try: | |
return ids[0] | |
except: | |
return '' | |
return '' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment