-
-
Notifications
You must be signed in to change notification settings - Fork 194
/
PloneBatch.py
65 lines (51 loc) · 2.48 KB
/
PloneBatch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# -*- coding: utf-8 -*-
from ZTUtils import make_query
from plone.batching.batch import QuantumBatch
from plone.batching.utils import calculate_pagerange
from zope.deprecation import deprecated
class Batch(QuantumBatch):
b_start_str = 'b_start'
def __init__(self, sequence, size, start=0, end=0, orphan=0,
overlap=0, pagerange=7, quantumleap=0,
b_start_str='b_start'):
super(Batch, self).__init__(sequence, size, start,
end, orphan, overlap,
pagerange, quantumleap)
self.b_start_str = b_start_str
def __len__(self):
return self.length
__len__ = deprecated(__len__,
('Using len() is deprecated. Use the `length` attribute for the '
'size of the current page, which is what we return now. '
'Use the `sequence_length` attribute for the size of the '
'entire sequence. '))
def __nonzero__(self):
# Without __nonzero__ a bool(self) would call len(self), which
# gives a deprecation warning.
return bool(self.length)
def initialize(self, start, end, size):
super(Batch, self).initialize(start, end, size)
self.pagerange, self.pagerangestart, self.pagerangeend = \
calculate_pagerange(self.pagenumber, self.numpages, self.pagerange)
def pageurl(self, formvariables, pagenumber=-1):
# Makes the url for a given page.
if pagenumber == -1:
pagenumber = self.pagenumber
b_start = pagenumber * (self.pagesize - self.overlap) - self.pagesize
return make_query(formvariables, {self.b_start_str: b_start})
def navurls(self, formvariables, navlist=None):
# Returns the page number and url for the navigation quick links.
if navlist is None:
navlist = []
if not navlist:
navlist = self.navlist
return map(lambda x, formvariables=formvariables:
(x, self.pageurl(formvariables, x)), navlist)
def prevurls(self, formvariables):
# Helper method to get prev navigation list from templates.
return self.navurls(formvariables, self.previous_pages)
def nexturls(self, formvariables):
# Helper method to get next navigation list from templates.
return self.navurls(formvariables, self.next_pages)
prevlist = QuantumBatch.previous_pages
nextlist = QuantumBatch.next_pages