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 >>> t = Template("{% load pagination_tags %}{% autopaginate var 2 %}{% paginate %}")
61 >>> from django.http import HttpRequest as DjangoHttpRequest
62 >>> class HttpRequest(DjangoHttpRequest):
65 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
66 u'\\n\\n<div class="pagination">...
68 >>> t = Template("{% load pagination_tags %}{% autopaginate var %}{% paginate %}")
69 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
70 u'\\n\\n<div class="pagination">...
71 >>> t = Template("{% load pagination_tags %}{% autopaginate var 20 %}{% paginate %}")
72 >>> t.render(Context({'var': range(21), 'request': HttpRequest()}))
73 u'\\n\\n<div class="pagination">...
74 >>> t = Template("{% load pagination_tags %}{% autopaginate var by %}{% paginate %}")
75 >>> t.render(Context({'var': range(21), 'by': 20, 'request': HttpRequest()}))
76 u'\\n\\n<div class="pagination">...
77 >>> t = Template("{% load pagination_tags %}{% autopaginate var by as foo %}{{ foo }}")
78 >>> t.render(Context({'var': range(21), 'by': 20, 'request': HttpRequest()}))
79 u'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]'
82 # Testing InfinitePaginator
84 >>> from paginator import InfinitePaginator
87 <class 'pagination.paginator.InfinitePaginator'>
88 >>> p = InfinitePaginator(range(20), 2, link_template='/bacon/page/%d')
89 >>> p.validate_number(2)
100 >>> p3.has_previous()
102 >>> p.page(10).has_next()
104 >>> p.page(1).has_previous()
108 >>> p3.previous_link()
111 # Testing FinitePaginator
113 >>> from paginator import FinitePaginator
116 <class 'pagination.paginator.FinitePaginator'>
117 >>> p = FinitePaginator(range(20), 2, offset=10, link_template='/bacon/page/%d')
118 >>> p.validate_number(2)
131 >>> p3.has_previous()
135 >>> p3.previous_link()
138 >>> p = FinitePaginator(range(20), 20, offset=10, link_template='/bacon/page/%d')
144 >>> p3.has_previous()
148 >>> p2.previous_link()
151 >>> from pagination.middleware import PaginationMiddleware
152 >>> from django.core.handlers.wsgi import WSGIRequest
153 >>> from StringIO import StringIO
154 >>> middleware = PaginationMiddleware()
155 >>> request = WSGIRequest({'REQUEST_METHOD': 'POST', 'CONTENT_TYPE': 'multipart', 'wsgi.input': StringIO()})
156 >>> middleware.process_request(request)
157 >>> request.upload_handlers.append('asdf')