2 >>> from django.core.paginator import Paginator
3 >>> from linaro_django_pagination.templatetags.pagination_tags import paginate
4 >>> from django.template import Template, Context
6 >>> p = Paginator(range(15), 2)
7 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
8 [1, 2, 3, 4, 5, 6, 7, 8]
10 >>> p = Paginator(range(17), 2)
11 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
12 [1, 2, 3, 4, 5, 6, 7, 8, 9]
14 >>> p = Paginator(range(19), 2)
15 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
16 [1, 2, 3, 4, None, 7, 8, 9, 10]
18 >>> p = Paginator(range(21), 2)
19 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
20 [1, 2, 3, 4, None, 8, 9, 10, 11]
23 >>> p = Paginator(range(5), 2, 1)
24 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
27 >>> p = Paginator(range(21), 2, 1)
28 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
29 [1, 2, 3, 4, None, 7, 8, 9, 10]
31 >>> p = Paginator(range(21), 2, 1)
32 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
33 [1, 2, 3, 4, None, 7, 8, 9, 10]
35 >>> p = Paginator(range(21), 2, 1)
36 >>> paginate({'paginator': p, 'page_obj': p.page(1)})['pages']
37 [1, 2, 3, 4, None, 7, 8, 9, 10]
39 >>> t = Template("{% load pagination_tags %}{% autopaginate var 2 %}{% paginate %}")
41 >>> from django.http import HttpRequest as DjangoHttpRequest
42 >>> class HttpRequest(DjangoHttpRequest):
43 ... page = lambda self, suffix: 1
45 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
46 u'\\n\\n<div class="pagination">...
48 >>> t = Template("{% load pagination_tags %}{% autopaginate var %}{% paginate %}")
49 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
50 u'\\n\\n<div class="pagination">...
51 >>> t = Template("{% load pagination_tags %}{% autopaginate var 20 %}{% paginate %}")
52 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
53 u'\\n\\n<div class="pagination">...
54 >>> t = Template("{% load pagination_tags %}{% autopaginate var by %}{% paginate %}")
55 >>> t.render(Context({'var': range(21), 'by': 20, 'request': HttpRequest()}))
56 u'\\n\\n<div class="pagination">...<a href="?page=2"...
57 >>> t = Template("{% load pagination_tags %}{% autopaginate var by as foo %}{{ foo }}")
58 >>> t.render(Context({'var': range(21), 'by': 20, 'request': HttpRequest()}))
59 u'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]'
61 >>> t = Template("{% load pagination_tags %}{% autopaginate var2 by as foo2 %}{% paginate %}{% autopaginate var by as foo %}{% paginate %}")
62 >>> t.render(Context({'var': range(21), 'var2': range(50, 121), 'by': 20, 'request': HttpRequest()}))
63 u'\\n\\n<div class="pagination">...<a href="?page_var2=2"...<a href="?page_var=2"...
66 # Testing InfinitePaginator
68 >>> from paginator import InfinitePaginator
71 <class 'linaro_django_pagination.paginator.InfinitePaginator'>
72 >>> p = InfinitePaginator(range(20), 2, link_template='/bacon/page/%d')
73 >>> p.validate_number(2)
86 >>> p.page(10).has_next()
88 >>> p.page(1).has_previous()
92 >>> p3.previous_link()
95 # Testing FinitePaginator
97 >>> from paginator import FinitePaginator
100 <class 'linaro_django_pagination.paginator.FinitePaginator'>
101 >>> p = FinitePaginator(range(20), 2, offset=10, link_template='/bacon/page/%d')
102 >>> p.validate_number(2)
115 >>> p3.has_previous()
119 >>> p3.previous_link()
122 >>> p = FinitePaginator(range(20), 20, offset=10, link_template='/bacon/page/%d')
128 >>> p3.has_previous()
132 >>> p2.previous_link()
135 >>> from linaro_django_pagination.middleware import PaginationMiddleware
136 >>> from django.core.handlers.wsgi import WSGIRequest
137 >>> from StringIO import StringIO
138 >>> middleware = PaginationMiddleware()
139 >>> request = WSGIRequest({'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': 'multipart', 'wsgi.input': StringIO()})
140 >>> middleware.process_request(request)
141 >>> request.upload_handlers.append('asdf')