2 >>> from django.core.paginator import Paginator
3 >>> from pagination.templatetags.pagination_tags import paginate
4 >>> from django.template import Template, Context
6 >>> p = Paginator(range(15), 2)
7 >>> pg = paginate({'paginator': p, 'page_obj': p.page(1)})
9 [1, 2, 3, 4, 5, 6, 7, 8]
10 >>> pg['records']['first']
12 >>> pg['records']['last']
15 >>> p = Paginator(range(15), 2)
16 >>> pg = paginate({'paginator': p, 'page_obj': p.page(8)})
18 [1, 2, 3, 4, 5, 6, 7, 8]
19 >>> pg['records']['first']
21 >>> pg['records']['last']
24 >>> p = Paginator(range(17), 2)
25 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
26 [1, 2, 3, 4, 5, 6, 7, 8, 9]
28 >>> p = Paginator(range(19), 2)
29 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
30 [1, 2, 3, 4, None, 7, 8, 9, 10]
32 >>> p = Paginator(range(21), 2)
33 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
34 [1, 2, 3, 4, None, 8, 9, 10, 11]
37 >>> p = Paginator(range(5), 2, 1)
38 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
41 >>> p = Paginator(range(21), 2, 1)
42 >>> pg = paginate({'paginator': p, 'page_obj': p.page(1)})
44 [1, 2, 3, 4, None, 7, 8, 9, 10]
45 >>> pg['records']['first']
47 >>> pg['records']['last']
50 >>> p = Paginator(range(21), 2, 1)
51 >>> pg = paginate({'paginator': p, 'page_obj': p.page(10)})
53 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
54 >>> pg['records']['first']
56 >>> pg['records']['last']
59 >>> p = Paginator(range(21), 2, 1)
60 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
61 [1, 2, 3, 4, None, 7, 8, 9, 10]
63 >>> t = Template("{% load pagination_tags %}{% autopaginate var 2 %}{% paginate %}")
65 >>> from django.http import HttpRequest as DjangoHttpRequest
66 >>> class HttpRequest(DjangoHttpRequest):
67 ... page = lambda self, suffix: 1
69 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
70 u'\\n\\n<div class="pagination">...
72 >>> t = Template("{% load pagination_tags %}{% autopaginate var %}{% paginate %}")
73 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
74 u'\\n\\n<div class="pagination">...
75 >>> t = Template("{% load pagination_tags %}{% autopaginate var 20 %}{% paginate %}")
76 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
77 u'\\n\\n<div class="pagination">...
78 >>> t = Template("{% load pagination_tags %}{% autopaginate var by %}{% paginate %}")
79 >>> t.render(Context({'var': range(21), 'by': 20, 'request': HttpRequest()}))
80 u'\\n\\n<div class="pagination">...<a href="?page=2"...
81 >>> t = Template("{% load pagination_tags %}{% autopaginate var by as foo %}{{ foo }}")
82 >>> t.render(Context({'var': range(21), 'by': 20, 'request': HttpRequest()}))
83 u'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]'
85 >>> t = Template("{% load pagination_tags %}{% autopaginate var2 by as foo2 %}{% paginate %}{% autopaginate var by as foo %}{% paginate %}")
86 >>> t.render(Context({'var': range(21), 'var2': range(50, 121), 'by': 20, 'request': HttpRequest()}))
87 u'\\n\\n<div class="pagination">...<a href="?page_var2=2"...<a href="?page_var=2"...
90 # Testing InfinitePaginator
92 >>> from paginator import InfinitePaginator
95 <class 'pagination.paginator.InfinitePaginator'>
96 >>> p = InfinitePaginator(range(20), 2, link_template='/bacon/page/%d')
97 >>> p.validate_number(2)
108 >>> p3.has_previous()
110 >>> p.page(10).has_next()
112 >>> p.page(1).has_previous()
116 >>> p3.previous_link()
119 # Testing FinitePaginator
121 >>> from paginator import FinitePaginator
124 <class 'pagination.paginator.FinitePaginator'>
125 >>> p = FinitePaginator(range(20), 2, offset=10, link_template='/bacon/page/%d')
126 >>> p.validate_number(2)
139 >>> p3.has_previous()
143 >>> p3.previous_link()
146 >>> p = FinitePaginator(range(20), 20, offset=10, link_template='/bacon/page/%d')
152 >>> p3.has_previous()
156 >>> p2.previous_link()
159 >>> from pagination.middleware import PaginationMiddleware
160 >>> from django.core.handlers.wsgi import WSGIRequest
161 >>> from StringIO import StringIO
162 >>> middleware = PaginationMiddleware()
163 >>> request = WSGIRequest({'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': 'multipart', 'wsgi.input': StringIO()})
164 >>> middleware.process_request(request)
165 >>> request.upload_handlers.append('asdf')