Fixed Width¶
Pagination navigation that does not grow or shrink depending on what position the current page.
Example
< *0* 1 2 3 4 ... 8 >
< 0 *1* 2 3 4 ... 8 >
< 0 1 *2* 3 4 ... 8 >
< 0 1 2 *3* 4 ... 8 >
< 0 ... 3 *4* 5 ... 8 >
< 0 ... 4 *5* 6 7 8 >
< 0 ... 4 5 *6* 7 8 >
< 0 ... 4 5 6 *7* 8 >
< 0 ... 4 5 6 7 *8* >
-
pagination.fixed.ascii_format(pagified)[source]¶ Format the result of pagify as an ASCII string.
Parameters: pagified (list) – The output of the pagify function. Example
from pagination.fixed import pagify, ascii_format for i in range(0, 9): print ascii_format(pagify(i, 9))
< * 0 * 1 2 3 4 ... 8 > < 0 * 1 * 2 3 4 ... 8 > < 0 1 * 2 * 3 4 ... 8 > < 0 1 2 * 3 * 4 ... 8 > < 0 ... 3 * 4 * 5 ... 8 > < 0 ... 4 * 5 * 6 7 8 > < 0 ... 4 5 * 6 * 7 8 > < 0 ... 4 5 6 * 7 * 8 > < 0 ... 4 5 6 7 * 8 * >
Returns: An ASCII formatted pagination string. Return type: str
-
pagination.fixed.pagify(page, pages, left_pages=1, right_pages=1, begin_pages=1, end_pages=1, include_ellipses=True)[source]¶ Return a list of page segments useful for displaying paginated navigation.
Parameters: - page (int) – The current page.
- pages (int) – The total number of pages. (Must be >= page.)
- left_pages (int) – The number of pages to show to the left of the current page. This is the exact number of pages shown if there are ellipses on both sides. However, there may be more pages shown to the left if the current page is near the end of the range, and less if the current page is near the beginning of the range.
- right_pages (int) – The number of pages to show to the right of the current page. This is the exact number of pages shown if there are ellipses on both sides. However, there may be more pages shown to the right if the current page is near the beginning of the range, and less if the current page is near the end of the range.
- begin_pages (int) – The number of pages to include at the beginning of the pagination list (before the ellipses, if they are present).
- end_pages (int) – The number of pages to include at the end of the pagination list (after the ellipses, if they are present).
Example
from pagination.fixed import pagify, ascii_format for i in range(0, 9): print pagify(i, 9)
[[], [], 0, [1, 2, 3, 4], ['...', 8]] [[], [0], 1, [2, 3, 4], ['...', 8]] [[], [0, 1], 2, [3, 4], ['...', 8]] [[], [0, 1, 2], 3, [4], ['...', 8]] [[0, '...'], [3], 4, [5], ['...', 8]] [[0, '...'], [4], 5, [6, 7, 8], []] [[0, '...'], [4, 5], 6, [7, 8], []] [[0, '...'], [4, 5, 6], 7, [8], []] [[0, '...'], [4, 5, 6, 7], 8, [], []]
Returns: [[start], [left], page, [right], [end]] Return type: list