changeset 63:52480306b641

Show only seven pagination links by default.
author Daniele Nicolodi <daniele@grinta.net>
date Sat, 13 Aug 2011 23:56:30 +0200
parents c3634ffa5a82
children f3ed8e9abf4a
files src/ltpdarepo/pagination.py src/ltpdarepo/tests/test_pagination.py
diffstat 2 files changed, 18 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/src/ltpdarepo/pagination.py	Sat Aug 13 23:56:23 2011 +0200
+++ b/src/ltpdarepo/pagination.py	Sat Aug 13 23:56:30 2011 +0200
@@ -1,7 +1,7 @@
 from math import ceil, floor
 
 class Pagination(object):
-    def __init__(self, page=1, count=10, size=10, items=9):
+    def __init__(self, page=1, count=10, size=10, items=7):
         self.current = page
         self.size = size
         self.count = count
--- a/src/ltpdarepo/tests/test_pagination.py	Sat Aug 13 23:56:23 2011 +0200
+++ b/src/ltpdarepo/tests/test_pagination.py	Sat Aug 13 23:56:30 2011 +0200
@@ -31,7 +31,7 @@
         self.assertEqual(l, [1, 2])
 
     def test_pages_without_ellipsis(self):
-        for i in range(1, 10):
+        for i in range(1, 8):
             p = Pagination(1, size*i, size)
             l = list(p)
             self.assertEqual(l, range(1, i + 1))
@@ -41,42 +41,42 @@
         npages = 15
         nitems = size*npages
 
-        for i in range(1, 6):
+        for i in range(1, 4):
             p = Pagination(i, nitems, size)
             l = list(p)
-            self.assertEqual(len(l), 9)
-            self.assertEqual(l, [1, 2, 3, 4, 5, 6, 7, -7, 15])
+            self.assertEqual(len(l), 7)
+            self.assertEqual(l, [1, 2, 3, 4, 5, -9, 15])
 
         p = Pagination(6, nitems, size)
         l = list(p)
-        self.assertEqual(len(l), 9)
-        self.assertEqual(l, [1, -2, 4, 5, 6, 7, 8, -6, 15])
+        self.assertEqual(len(l), 7)
+        self.assertEqual(l, [1, -3, 5, 6, 7, -7, 15])
 
         p = Pagination(7, nitems, size)
         l = list(p)
-        self.assertEqual(len(l), 9)
-        self.assertEqual(l, [1, -3, 5, 6, 7, 8, 9, -5, 15])
+        self.assertEqual(len(l), 7)
+        self.assertEqual(l, [1, -4, 6, 7, 8, -6, 15])
 
         p = Pagination(8, nitems, size)
         l = list(p)
-        self.assertEqual(len(l), 9)
-        self.assertEqual(l, [1, -4, 6, 7, 8, 9, 10, -4, 15])
+        self.assertEqual(len(l), 7)
+        self.assertEqual(l, [1, -5, 7, 8, 9, -5, 15])
 
         p = Pagination(9, nitems, size)
         l = list(p)
-        self.assertEqual(len(l), 9)
-        self.assertEqual(l, [1, -5, 7, 8, 9, 10, 11, -3, 15])
+        self.assertEqual(len(l), 7)
+        self.assertEqual(l, [1, -6, 8, 9, 10, -4, 15])
 
         p = Pagination(10, nitems, size)
         l = list(p)
-        self.assertEqual(len(l), 9)
-        self.assertEqual(l, [1, -6, 8, 9, 10, 11, 12, -2, 15])
+        self.assertEqual(len(l), 7)
+        self.assertEqual(l, [1, -7, 9, 10, 11, -3, 15])
 
-        for i in range(11, 15):
+        for i in range(12, 15):
             p = Pagination(i, nitems, size)
             l = list(p)
-            self.assertEqual(len(l), 9)
-            self.assertEqual(l, [1, -7, 9, 10, 11, 12, 13, 14, 15])
+            self.assertEqual(len(l), 7)
+            self.assertEqual(l, [1, -9, 11, 12, 13, 14, 15])
 
 
 if __name__ == '__main__':