Merge lp:~elachuni/ubuntu-webcatalog/improve-pagination-widget into lp:ubuntu-webcatalog

Proposed by Anthony Lenton
Status: Merged
Approved by: Anthony Lenton
Approved revision: 43
Merged at revision: 42
Proposed branch: lp:~elachuni/ubuntu-webcatalog/improve-pagination-widget
Merge into: lp:ubuntu-webcatalog
Diff against target: 177 lines (+81/-16)
5 files modified
src/webcatalog/static/css/webcatalog.css (+11/-0)
src/webcatalog/templates/webcatalog/batch_navigation.html (+30/-7)
src/webcatalog/templatetags/webcatalog.py (+6/-0)
src/webcatalog/tests/test_templatetags.py (+26/-3)
src/webcatalog/tests/test_views.py (+8/-6)
To merge this branch: bzr merge lp:~elachuni/ubuntu-webcatalog/improve-pagination-widget
Reviewer Review Type Date Requested Status
Ricardo Kirkner (community) Approve
Review via email: mp+68439@code.launchpad.net

Commit message

Improvements for the pagination widget.

Description of the change

Overview
========
This branch improves the pagination widget by implementing the recommendations on
http://developer.yahoo.com/ypatterns/navigation/pagination/search.html

Details
=======
You can see samples of the rendered resulting widget on
http://people.canonical.com/~anthony/Selection_003.png
http://people.canonical.com/~anthony/Selection_004.png
http://people.canonical.com/~anthony/Selection_005.png

To post a comment you must log in.
43. By Anthony Lenton

Added visble_page_range testcase to tests that are actually run.

Revision history for this message
Ricardo Kirkner (ricardokirkner) wrote :

LGTM.

Don't like how the second screenshot displays '1 to 1 of 1' twice in a very short 'space', but that's work for a different mp probably.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/webcatalog/static/css/webcatalog.css'
--- src/webcatalog/static/css/webcatalog.css 2011-07-04 14:47:05 +0000
+++ src/webcatalog/static/css/webcatalog.css 2011-07-19 18:35:13 +0000
@@ -246,3 +246,14 @@
246}246}
247247
248/* End breadcrumbs style */248/* End breadcrumbs style */
249
250.paginator p {
251 text-align: center;
252}
253.paginator .arrow a {
254 font-size: 16px;
255}
256
257.paginator p, .paginator a {
258 font-size: 14px;
259}
249260
=== added file 'src/webcatalog/static/images/arrow_next.png'
250Binary files src/webcatalog/static/images/arrow_next.png 1970-01-01 00:00:00 +0000 and src/webcatalog/static/images/arrow_next.png 2011-07-19 18:35:13 +0000 differ261Binary files src/webcatalog/static/images/arrow_next.png 1970-01-01 00:00:00 +0000 and src/webcatalog/static/images/arrow_next.png 2011-07-19 18:35:13 +0000 differ
=== added file 'src/webcatalog/static/images/arrow_previous.png'
251Binary files src/webcatalog/static/images/arrow_previous.png 1970-01-01 00:00:00 +0000 and src/webcatalog/static/images/arrow_previous.png 2011-07-19 18:35:13 +0000 differ262Binary files src/webcatalog/static/images/arrow_previous.png 1970-01-01 00:00:00 +0000 and src/webcatalog/static/images/arrow_previous.png 2011-07-19 18:35:13 +0000 differ
=== modified file 'src/webcatalog/templates/webcatalog/batch_navigation.html'
--- src/webcatalog/templates/webcatalog/batch_navigation.html 2011-06-27 13:00:56 +0000
+++ src/webcatalog/templates/webcatalog/batch_navigation.html 2011-07-19 18:35:13 +0000
@@ -1,11 +1,34 @@
1{% load i18n %}1{% load i18n %}
2 {% if page.has_previous %}2{% load webcatalog %}
3 <a href="?{% if query %}q={{ query }}&{% endif %}page={{ page.previous_page_number }}">{% trans "prev" %}</a>3<div class="paginator">
4 {% endif %}
5 {% blocktrans with start_index=page.start_index end_index=page.end_index count=page.paginator.count %}4 {% blocktrans with start_index=page.start_index end_index=page.end_index count=page.paginator.count %}
6 {{ start_index }} to {{ end_index }} of {{ count }}5 <p>Displaying items {{ start_index }} to {{ end_index }} of {{ count }}</p>
7 {% endblocktrans %}6 {% endblocktrans %}
7 {% if page.has_other_pages %}
8 <p>
9 {% if page.has_previous %}
10 <span class="arrow">
11 <a href="?{% if query %}q={{ query }}&{% endif %}page={{ page.previous_page_number }}">
12 {% trans "Prev" %}</a>
13 <a href="?{% if query %}q={{ query }}&{% endif %}page={{ page.previous_page_number }}">
14 <img src="{{ STATIC_URL }}images/arrow_previous.png"/></a>
15 </span>
16 {% endif %}
17 {% for i in page|visible_page_range %}
18 {% ifequal i page.number %}
19 {{i}}
20 {% else %}
21 <a href="?{% if query %}q={{ query }}&{% endif %}page={{ i }}">{{ i }}</a>
22 {% endifequal %}
23 {% endfor %}
8 {% if page.has_next %}24 {% if page.has_next %}
9 <a href="?{% if query %}q={{ query }}&{% endif %}page={{ page.next_page_number }}">{% trans "next" %}</a>25 <span class="arrow">
10 {% endif %}26 <a href="?{% if query %}q={{ query }}&{% endif %}page={{ page.next_page_number }}">
1127 <img src="{{ STATIC_URL }}images/arrow_next.png"/></a>
28 <a href="?{% if query %}q={{ query }}&{% endif %}page={{ page.next_page_number }}">
29 {% trans "Next" %}</a>
30 </span>
31 {% endif %}
32 </p>
33 {% endif %}
34</div>
1235
=== modified file 'src/webcatalog/templatetags/webcatalog.py'
--- src/webcatalog/templatetags/webcatalog.py 2011-07-04 14:47:05 +0000
+++ src/webcatalog/templatetags/webcatalog.py 2011-07-19 18:35:13 +0000
@@ -171,3 +171,9 @@
171 if inside_li:171 if inside_li:
172 html += "</ul>"172 html += "</ul>"
173 return mark_safe(html)173 return mark_safe(html)
174
175@register.filter
176def visible_page_range(page):
177 first = max(page.number - 5, 1)
178 last = min(first + 10, page.paginator.num_pages + 1)
179 return range(first, last)
174\ No newline at end of file180\ No newline at end of file
175181
=== modified file 'src/webcatalog/tests/test_templatetags.py'
--- src/webcatalog/tests/test_templatetags.py 2011-07-04 20:17:45 +0000
+++ src/webcatalog/tests/test_templatetags.py 2011-07-19 18:35:13 +0000
@@ -26,17 +26,20 @@
2626
27from django.core.urlresolvers import reverse27from django.core.urlresolvers import reverse
28from django.template import Context28from django.template import Context
29from mock import Mock
2930
30from webcatalog.templatetags.webcatalog import (31from webcatalog.templatetags.webcatalog import (
31 htmlize_package_description,32 htmlize_package_description,
32 install_options,33 install_options,
34 visible_page_range,
33 )35 )
34from webcatalog.tests.factory import TestCaseWithFactory36from webcatalog.tests.factory import TestCaseWithFactory
3537
36__metaclass__ = type38__metaclass__ = type
37__all__ = [39__all__ = [
38 'InstallOptionsTestCase',40 'InstallOptionsTestCase',
39 'TestHtmlize',41 'HtmlizePackageDescriptionTestCase',
42 'VisiblePageRangeTestCase',
40 ]43 ]
4144
4245
@@ -234,7 +237,7 @@
234 * Extensible with plugins237 * Extensible with plugins
235"""238"""
236239
237class TestHtmlize(unittest.TestCase):240class HtmlizePackageDescriptionTestCase(unittest.TestCase):
238 def test_htmlize(self):241 def test_htmlize(self):
239 for descr in [d1, d2, d3]:242 for descr in [d1, d2, d3]:
240 html_descr = htmlize_package_description(descr)243 html_descr = htmlize_package_description(descr)
@@ -263,4 +266,24 @@
263 html_descr = htmlize_package_description(descr)266 html_descr = htmlize_package_description(descr)
264 li_count = html_descr.count("<li>")267 li_count = html_descr.count("<li>")
265 self.assertEqual(3, li_count)268 self.assertEqual(3, li_count)
266
267\ No newline at end of file269\ No newline at end of file
270
271class VisiblePageRangeTestCase(unittest.TestCase):
272 def test_visible_page_range(self):
273 cases = [
274 ( 2, 1, [1, 2]),
275 (20, 1, range(1, 11)),
276 ( 3, 2, [1, 2, 3]),
277 (20, 2, range(1, 11)),
278 ( 4, 4, [1, 2, 3, 4]),
279 (20, 8, range(3, 13)),
280 ( 8, 8, range(3, 9)),
281 (20, 18, range(13, 21)),
282 (400, 400, range(395, 401)),
283 ]
284 for num_pages, current_page, expected in cases:
285 page = Mock()
286 page.number = current_page
287 page.paginator.num_pages = num_pages
288 result = visible_page_range(page)
289 self.assertTrue(len(result) <= 10)
290 self.assertEqual(expected, result)
268291
=== modified file 'src/webcatalog/tests/test_views.py'
--- src/webcatalog/tests/test_views.py 2011-07-07 20:54:45 +0000
+++ src/webcatalog/tests/test_views.py 2011-07-19 18:35:13 +0000
@@ -313,9 +313,10 @@
313 self.assertEqual(3, page.paginator.count)313 self.assertEqual(3, page.paginator.count)
314 self.assertEqual(2, page.next_page_number())314 self.assertEqual(2, page.next_page_number())
315315
316 # And we have two references to the 'next' link, one at the top316 # And we have six references to the next page, three at the top
317 # and one at the bottom.317 # and three at the bottom, as you have the linked "2" number, plus the
318 self.assertContains(response, '<a href="?q=fo&page=2"', 2)318 # arrow and text "Next" link.
319 self.assertContains(response, '<a href="?q=fo&page=2"', 6)
319320
320 def test_invalid_page_doesnt_error(self):321 def test_invalid_page_doesnt_error(self):
321 distro = self.factory.make_distroseries(code_name='lucid')322 distro = self.factory.make_distroseries(code_name='lucid')
@@ -396,9 +397,10 @@
396 self.assertEqual(3, page.paginator.count)397 self.assertEqual(3, page.paginator.count)
397 self.assertEqual(2, page.next_page_number())398 self.assertEqual(2, page.next_page_number())
398399
399 # And we have two references to the 'next' link, one at the top400 # And we have six references to the next page, three at the top
400 # and one at the bottom.401 # and three at the bottom, as you have the linked "2" number, plus the
401 self.assertContains(response, '<a href="?page=2"', 2)402 # arrow and text "Next" link.
403 self.assertContains(response, '<a href="?page=2"', 6)
402404
403 def test_invalid_page_doesnt_error(self):405 def test_invalid_page_doesnt_error(self):
404 dept = self.factory.make_department('bar')406 dept = self.factory.make_department('bar')

Subscribers

People subscribed via source and target branches