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 >>> 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 >>> t = Template("{% load pagination_tags %}{% autopaginate var 2 %}{% paginate %}")
33 >>> from django.http import HttpRequest as DjangoHttpRequest
34 >>> class HttpRequest(DjangoHttpRequest):
37 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
38 u'\\n\\n<div class="pagination">...
40 >>> t = Template("{% load pagination_tags %}{% autopaginate var %}{% paginate %}")
41 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
42 u'\\n\\n<div class="pagination">...
43 >>> t = Template("{% load pagination_tags %}{% autopaginate var 20 %}{% paginate %}")
44 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
45 u'\\n\\n<div class="pagination">...
46 >>> t = Template("{% load pagination_tags %}{% autopaginate var by %}{% paginate %}")
47 >>> t.render(Context({'var': range(21), 'by': 20, 'request': HttpRequest()}))
48 u'\\n\\n<div class="pagination">...
49 >>> t = Template("{% load pagination_tags %}{% autopaginate var by as foo %}{{ foo }}")
50 >>> t.render(Context({'var': range(21), 'by': 20, 'request': HttpRequest()}))
51 u'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]'
54 # Testing InfinitePaginator
56 >>> from paginator import InfinitePaginator
59 <class 'pagination.paginator.InfinitePaginator'>
60 >>> p = InfinitePaginator(range(20), 2, link_template='/bacon/page/%d')
61 >>> p.validate_number(2)
74 >>> p.page(10).has_next()
76 >>> p.page(1).has_previous()
80 >>> p3.previous_link()
83 # Testing FinitePaginator
85 >>> from paginator import FinitePaginator
88 <class 'pagination.paginator.FinitePaginator'>
89 >>> p = FinitePaginator(range(20), 2, offset=10, link_template='/bacon/page/%d')
90 >>> p.validate_number(2)
103 >>> p3.has_previous()
107 >>> p3.previous_link()
110 >>> p = FinitePaginator(range(20), 20, offset=10, link_template='/bacon/page/%d')
116 >>> p3.has_previous()
120 >>> p2.previous_link()
123 >>> from pagination.middleware import PaginationMiddleware
124 >>> from django.core.handlers.wsgi import WSGIRequest
125 >>> from StringIO import StringIO
126 >>> middleware = PaginationMiddleware()
127 >>> request = WSGIRequest({'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': 'multipart', 'wsgi.input': StringIO()})
128 >>> middleware.process_request(request)
129 >>> request.upload_handlers.append('asdf')