##// END OF EJS Templates
Divided paginator with page range
neko259 -
r1199:e9ba1d7d default
parent child Browse files
Show More
@@ -2,7 +2,7 b''
2
2
3 from django.core.paginator import Paginator
3 from django.core.paginator import Paginator
4
4
5 PAGINATOR_LOOKAROUND_SIZE = 3
5 PAGINATOR_LOOKAROUND_SIZE = 2
6
6
7
7
8 def get_paginator(*args, **kwargs):
8 def get_paginator(*args, **kwargs):
@@ -14,9 +14,39 b' class DividedPaginator(Paginator):'
14 lookaround_size = PAGINATOR_LOOKAROUND_SIZE
14 lookaround_size = PAGINATOR_LOOKAROUND_SIZE
15 current_page = 0
15 current_page = 0
16
16
17 def left_range(self):
18 return self.page_range[:self.lookaround_size]
19
20 def right_range(self):
21 pages = self.num_pages-self.lookaround_size
22 if pages <= 0:
23 return []
24 else:
25 return self.page_range[pages:]
26
17 def center_range(self):
27 def center_range(self):
18 index = self.page_range.index(self.current_page)
28 index = self.page_range.index(self.current_page)
19
29
20 start = max(0, index - self.lookaround_size)
30 start = max(self.lookaround_size, index - self.lookaround_size)
21 end = min(len(self.page_range), index + self.lookaround_size + 1)
31 end = min(self.num_pages - self.lookaround_size, index + self.lookaround_size + 1)
22 return self.page_range[start:end] No newline at end of file
32 return self.page_range[start:end]
33
34 def divided_range(self):
35 dr = list()
36
37 dr += self.left_range()
38 dr += self.center_range()
39 dr += self.right_range()
40
41 # Remove duplicates
42 dr = list(set(dr))
43 dr.sort()
44
45 return dr
46
47 def get_left_divider(self):
48 return self.lookaround_size + 1
49
50 def get_right_divider(self):
51 return self.num_pages - self.lookaround_size + 1
52
@@ -141,15 +141,8 b''
141 <span class="metapanel">
141 <span class="metapanel">
142 <b><a href="{% url "authors" %}">{{ site_name }}</a> {{ version }}</b>
142 <b><a href="{% url "authors" %}">{{ site_name }}</a> {{ version }}</b>
143 {% trans "Pages:" %}
143 {% trans "Pages:" %}
144 <a href="
145 {% if tag %}
146 {% url "tag" tag_name=tag.name page=paginator.page_range|first %}
147 {% else %}
148 {% url "index" page=paginator.page_range|first %}
149 {% endif %}
150 ">&lt;&lt;</a>
151 [
144 [
152 {% for page in paginator.center_range %}
145 {% for page in paginator.divided_range %}
153 <a
146 <a
154 {% ifequal page current_page.number %}
147 {% ifequal page current_page.number %}
155 class="current_page"
148 class="current_page"
@@ -164,13 +157,6 b''
164 {% if not forloop.last %},{% endif %}
157 {% if not forloop.last %},{% endif %}
165 {% endfor %}
158 {% endfor %}
166 ]
159 ]
167 <a href="
168 {% if tag %}
169 {% url "tag" tag_name=tag.name page=paginator.page_range|last %}
170 {% else %}
171 {% url "index" page=paginator.page_range|last %}
172 {% endif %}
173 ">&gt;&gt;</a>
174 [<a href="rss/">RSS</a>]
160 [<a href="rss/">RSS</a>]
175 </span>
161 </span>
176
162
@@ -51,11 +51,8 b''
51 <span class="metapanel">
51 <span class="metapanel">
52 <b><a href="{% url "authors" %}">{{ site_name }}</a> {{ version }}</b>
52 <b><a href="{% url "authors" %}">{{ site_name }}</a> {{ version }}</b>
53 {% trans "Pages:" %}
53 {% trans "Pages:" %}
54 <a href="
55 {% url "feed" page=paginator.page_range|first %}
56 ">&lt;&lt;</a>
57 [
54 [
58 {% for page in paginator.center_range %}
55 {% for page in paginator.divided_range %}
59 <a
56 <a
60 {% ifequal page current_page.number %}
57 {% ifequal page current_page.number %}
61 class="current_page"
58 class="current_page"
@@ -66,9 +63,6 b''
66 {% if not forloop.last %},{% endif %}
63 {% if not forloop.last %},{% endif %}
67 {% endfor %}
64 {% endfor %}
68 ]
65 ]
69 <a href="
70 {% url "feed" page=paginator.page_range|last %}
71 ">&gt;&gt;</a>
72 </span>
66 </span>
73
67
74 {% endblock %}
68 {% endblock %}
General Comments 0
You need to be logged in to leave comments. Login now