mirror of
git://git.yoctoproject.org/layerindex-web.git
synced 2025-07-19 20:59:01 +02:00
Replace custom pagination with django-bootstrap-pagination
Simplify things a bit. We lose the digg-style pagination but the new behaviour is good enough and improves maintainability. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
This commit is contained in:
parent
513be9d8ef
commit
f527692c7c
|
@ -155,6 +155,7 @@ INSTALLED_APPS = (
|
||||||
'axes',
|
'axes',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'corsheaders',
|
'corsheaders',
|
||||||
|
'bootstrap_pagination',
|
||||||
)
|
)
|
||||||
|
|
||||||
AUTHENTICATION_BACKENDS = [
|
AUTHENTICATION_BACKENDS = [
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
# Borrowed from http://djangosnippets.org/snippets/361/
|
|
||||||
# Original author: johan de taeye
|
|
||||||
# With modifications from Ludwik Trammer
|
|
||||||
#
|
|
||||||
# Adds GET parameters to the current URL
|
|
||||||
|
|
||||||
from django.template import Library, Node, TemplateSyntaxError, Variable
|
|
||||||
|
|
||||||
register = Library()
|
|
||||||
|
|
||||||
class AddParameter(Node):
|
|
||||||
def __init__(self, varname, value):
|
|
||||||
self.varname = Variable(varname)
|
|
||||||
self.value = Variable(value)
|
|
||||||
|
|
||||||
def render(self, context):
|
|
||||||
req = Variable('request').resolve(context)
|
|
||||||
params = req.GET.copy()
|
|
||||||
params[self.varname.resolve(context)] = self.value.resolve(context)
|
|
||||||
return '%s?%s' % (req.path, params.urlencode())
|
|
||||||
|
|
||||||
def addurlparameter(parser, token):
|
|
||||||
from re import split
|
|
||||||
bits = split(r'\s+', token.contents, 2)
|
|
||||||
if len(bits) < 2:
|
|
||||||
raise TemplateSyntaxError("'%s' tag requires two arguments" % bits[0])
|
|
||||||
return AddParameter(bits[1],bits[2])
|
|
||||||
|
|
||||||
register.tag('addurlparameter', addurlparameter)
|
|
|
@ -1,52 +0,0 @@
|
||||||
# Borrowed from http://djangosnippets.org/snippets/2199/
|
|
||||||
#
|
|
||||||
# Digg-like page numbering using inclusion tag
|
|
||||||
|
|
||||||
from django import template
|
|
||||||
|
|
||||||
register = template.Library()
|
|
||||||
|
|
||||||
@register.inclusion_tag('pagination.html', takes_context=True)
|
|
||||||
def pagination(context, page, begin_pages=2, end_pages=2, before_current_pages=4, after_current_pages=4):
|
|
||||||
# Digg-like pages
|
|
||||||
before = max(page.number - before_current_pages - 1, 0)
|
|
||||||
after = page.number + after_current_pages
|
|
||||||
|
|
||||||
begin = page.paginator.page_range[:begin_pages]
|
|
||||||
middle = page.paginator.page_range[before:after]
|
|
||||||
end = page.paginator.page_range[-end_pages:]
|
|
||||||
last_page_number = end[-1]
|
|
||||||
|
|
||||||
def collides(firstlist, secondlist):
|
|
||||||
""" Returns true if lists collides (have same entries)
|
|
||||||
|
|
||||||
>>> collides([1,2,3,4],[3,4,5,6,7])
|
|
||||||
True
|
|
||||||
>>> collides([1,2,3,4],[5,6,7])
|
|
||||||
False
|
|
||||||
"""
|
|
||||||
return any(item in secondlist for item in firstlist)
|
|
||||||
|
|
||||||
# If middle and end has same entries, then end is what we want
|
|
||||||
if collides(middle, end):
|
|
||||||
end = range(max(page.number-before_current_pages, 1), last_page_number+1)
|
|
||||||
|
|
||||||
middle = []
|
|
||||||
|
|
||||||
# If begin and middle ranges has same entries, then begin is what we want
|
|
||||||
if collides(begin, middle):
|
|
||||||
begin = range(1, min(page.number + after_current_pages, last_page_number)+1)
|
|
||||||
|
|
||||||
middle = []
|
|
||||||
|
|
||||||
# If begin and end has same entries then begin is what we want
|
|
||||||
if collides(begin, end):
|
|
||||||
begin = range(1, last_page_number+1)
|
|
||||||
end = []
|
|
||||||
|
|
||||||
context.update({'page' : page,
|
|
||||||
'begin' : begin,
|
|
||||||
'middle' : middle,
|
|
||||||
'end' : end})
|
|
||||||
|
|
||||||
return context
|
|
|
@ -7,6 +7,7 @@ confusable-homoglyphs==3.2.0
|
||||||
Django>=1.11.20,<1.12
|
Django>=1.11.20,<1.12
|
||||||
django-appconf==1.0.3
|
django-appconf==1.0.3
|
||||||
django-axes==4.5.4
|
django-axes==4.5.4
|
||||||
|
django-bootstrap-pagination==1.7.1
|
||||||
django-cors-headers==2.5.3
|
django-cors-headers==2.5.3
|
||||||
django-ipware==2.1.0
|
django-ipware==2.1.0
|
||||||
django-ranged-response==0.2.0
|
django-ranged-response==0.2.0
|
||||||
|
|
|
@ -155,6 +155,7 @@ INSTALLED_APPS = (
|
||||||
'axes',
|
'axes',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'corsheaders',
|
'corsheaders',
|
||||||
|
'bootstrap_pagination',
|
||||||
)
|
)
|
||||||
|
|
||||||
AUTHENTICATION_BACKENDS = [
|
AUTHENTICATION_BACKENDS = [
|
||||||
|
|
|
@ -90,8 +90,10 @@
|
||||||
<input type="submit" class="btn btn-default" name="add_all" value="Add all"></input>
|
<input type="submit" class="btn btn-default" name="add_all" value="Add all"></input>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if searched %}
|
{% if searched %}
|
||||||
|
|
|
@ -62,8 +62,10 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if search_keyword %}
|
{% if search_keyword %}
|
||||||
|
|
|
@ -287,8 +287,10 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if searched %}
|
{% if searched %}
|
||||||
|
|
|
@ -65,8 +65,10 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if search_keyword %}
|
{% if search_keyword %}
|
||||||
|
|
|
@ -60,8 +60,10 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -105,8 +105,10 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No matching layers in database.</p>
|
<p>No matching layers in database.</p>
|
||||||
|
|
|
@ -64,8 +64,10 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if search_keyword %}
|
{% if search_keyword %}
|
||||||
|
|
|
@ -71,8 +71,10 @@
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
{% if search_keyword %}
|
{% if search_keyword %}
|
||||||
|
|
|
@ -69,8 +69,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
<p>No unpublished layers to review.</p>
|
<p>No unpublished layers to review.</p>
|
||||||
|
|
|
@ -54,8 +54,10 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% if is_paginated %}
|
{% if is_paginated %}
|
||||||
{% load pagination %}
|
{% load bootstrap_pagination %}
|
||||||
{% pagination page_obj %}
|
<div class="text-center">
|
||||||
|
{% bootstrap_paginate page_obj range=10 show_prev_next="false" show_first_last="true" %}
|
||||||
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% endautoescape %}
|
{% endautoescape %}
|
||||||
|
|
|
@ -1,57 +0,0 @@
|
||||||
{% comment %}
|
|
||||||
|
|
||||||
layerindex-web - pagination template
|
|
||||||
|
|
||||||
Copyright (C) 2013 Intel Corporation
|
|
||||||
Licensed under the MIT license, see COPYING.MIT for details
|
|
||||||
|
|
||||||
{% endcomment %}
|
|
||||||
|
|
||||||
{% load addurlparameter %}
|
|
||||||
|
|
||||||
<nav class="text-center">
|
|
||||||
<ul class="pagination">
|
|
||||||
{% if page.has_previous %}
|
|
||||||
<li><a href="{% addurlparameter 'page' page.previous_page_number %}">prev</a></li>
|
|
||||||
{% else %}
|
|
||||||
<li class="disabled"><span>prev</span></li>
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
|
|
||||||
{% for pnum in begin %}
|
|
||||||
{% if pnum == page.number %}
|
|
||||||
<li class="active"><a href="#">{{ page.number }}</a></li>
|
|
||||||
{% else %}
|
|
||||||
<li><a href="{% addurlparameter 'page' pnum %}">{{ pnum }}</a></li>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
|
|
||||||
{% if middle %}
|
|
||||||
<li class="disabled"><span>...</span></li>
|
|
||||||
{% for pnum in middle %}
|
|
||||||
{% if pnum == page.number %}
|
|
||||||
<li class="active"><span>{{ page.number }}</span></li>
|
|
||||||
{% else %}
|
|
||||||
<li><a href="{% addurlparameter 'page' pnum %}">{{ pnum }}</a></li>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if end %}
|
|
||||||
<li class="disabled"><span>...</span></li>
|
|
||||||
{% for pnum in end %}
|
|
||||||
{% if pnum == page.number %}
|
|
||||||
<li class="active"><span>{{ page.number }}</span></li>
|
|
||||||
{% else %}
|
|
||||||
<li><a href="{% addurlparameter 'page' pnum %}">{{ pnum }}</a></li>
|
|
||||||
{% endif %}
|
|
||||||
{% endfor %}
|
|
||||||
{% endif %}
|
|
||||||
|
|
||||||
{% if page.has_next %}
|
|
||||||
<li><a href="{% addurlparameter 'page' page.next_page_number %}">next</a></li>
|
|
||||||
{% else %}
|
|
||||||
<li class="disabled"><span>next</span></li>
|
|
||||||
{% endif %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
Loading…
Reference in New Issue
Block a user