##// END OF EJS Templates
Pretty divided paginator with ellipsis
neko259 -
r1200:570dd244 default
parent child Browse files
Show More
@@ -14,29 +14,29 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):
17 def _left_range(self):
18 return self.page_range[:self.lookaround_size]
18 return self.page_range[:self.lookaround_size]
19
19
20 def right_range(self):
20 def _right_range(self):
21 pages = self.num_pages-self.lookaround_size
21 pages = self.num_pages-self.lookaround_size
22 if pages <= 0:
22 if pages <= 0:
23 return []
23 return []
24 else:
24 else:
25 return self.page_range[pages:]
25 return self.page_range[pages:]
26
26
27 def center_range(self):
27 def _center_range(self):
28 index = self.page_range.index(self.current_page)
28 index = self.page_range.index(self.current_page)
29
29
30 start = max(self.lookaround_size, index - self.lookaround_size)
30 start = max(self.lookaround_size, index - self.lookaround_size)
31 end = min(self.num_pages - self.lookaround_size, index + self.lookaround_size + 1)
31 end = min(self.num_pages - self.lookaround_size, index + self.lookaround_size + 1)
32 return self.page_range[start:end]
32 return self.page_range[start:end]
33
33
34 def divided_range(self):
34 def get_divided_range(self):
35 dr = list()
35 dr = list()
36
36
37 dr += self.left_range()
37 dr += self._left_range()
38 dr += self.center_range()
38 dr += self._center_range()
39 dr += self.right_range()
39 dr += self._right_range()
40
40
41 # Remove duplicates
41 # Remove duplicates
42 dr = list(set(dr))
42 dr = list(set(dr))
@@ -44,9 +44,18 b' class DividedPaginator(Paginator):'
44
44
45 return dr
45 return dr
46
46
47 def get_left_divider(self):
47 def get_dividers(self):
48 return self.lookaround_size + 1
48 dividers = []
49
50 prev_page = 1
51 for page in self.get_divided_range():
52 if page - prev_page > 1:
53 dividers.append(page)
49
54
50 def get_right_divider(self):
55 # There can be no more than 2 dividers, so don't bother going
51 return self.num_pages - self.lookaround_size + 1
56 # further
57 if len(dividers) > 2:
58 break
59 prev_page = page
52
60
61 return dividers
@@ -142,20 +142,25 b''
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 [
144 [
145 {% for page in paginator.divided_range %}
145 {% with dividers=paginator.get_dividers %}
146 <a
146 {% for page in paginator.get_divided_range %}
147 {% ifequal page current_page.number %}
147 {% if page in dividers %}
148 class="current_page"
148 …,
149 {% endifequal %}
149 {% endif %}
150 href="
150 <a
151 {% if tag %}
151 {% ifequal page current_page.number %}
152 {% url "tag" tag_name=tag.name page=page %}
152 class="current_page"
153 {% else %}
153 {% endifequal %}
154 {% url "index" page=page %}
154 href="
155 {% endif %}
155 {% if tag %}
156 ">{{ page }}</a>
156 {% url "tag" tag_name=tag.name page=page %}
157 {% if not forloop.last %},{% endif %}
157 {% else %}
158 {% endfor %}
158 {% url "index" page=page %}
159 {% endif %}
160 ">{{ page }}</a>
161 {% if not forloop.last %},{% endif %}
162 {% endfor %}
163 {% endwith %}
159 ]
164 ]
160 [<a href="rss/">RSS</a>]
165 [<a href="rss/">RSS</a>]
161 </span>
166 </span>
@@ -52,16 +52,21 b''
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 [
54 [
55 {% for page in paginator.divided_range %}
55 {% with dividers=paginator.get_dividers %}
56 <a
56 {% for page in paginator.get_divided_range %}
57 {% ifequal page current_page.number %}
57 {% if page in dividers %}
58 class="current_page"
58 …,
59 {% endifequal %}
59 {% endif %}
60 href="
60 <a
61 {% url "feed" page=page %}
61 {% ifequal page current_page.number %}
62 ">{{ page }}</a>
62 class="current_page"
63 {% if not forloop.last %},{% endif %}
63 {% endifequal %}
64 {% endfor %}
64 href="
65 {% url "feed" page=page %}
66 ">{{ page }}</a>
67 {% if not forloop.last %},{% endif %}
68 {% endfor %}
69 {% endwith %}
65 ]
70 ]
66 </span>
71 </span>
67
72
General Comments 0
You need to be logged in to leave comments. Login now