1 | Index: paginator.py
|
---|
2 | ===================================================================
|
---|
3 | --- paginator.py (revision 1066)
|
---|
4 | +++ paginator.py (working copy)
|
---|
5 | @@ -56,6 +56,29 @@
|
---|
6 |
|
---|
7 | def has_previous_page(self, page_number):
|
---|
8 | return page_number > 0
|
---|
9 | +
|
---|
10 | + def first_on_page(self, page_number):
|
---|
11 | + "Returns the # of the first object on the current page relative to total objects found (hits)."
|
---|
12 | + if page_number == 0:
|
---|
13 | + return page_number + 1
|
---|
14 | + else:
|
---|
15 | + return (self.num_per_page * page_number) + 1
|
---|
16 | +
|
---|
17 | + def last_on_page(self, page_number):
|
---|
18 | + "Returns the # of the last object on the current page relative to total objects found (hits)."
|
---|
19 | + hits_,pages_ = self.hits,self.pages
|
---|
20 | + if page_number == 0: #first page
|
---|
21 | + if self.num_per_page >= hits_:
|
---|
22 | + return hits_
|
---|
23 | + else:
|
---|
24 | + return self.num_per_page
|
---|
25 | + elif page_number == (pages_ - 1): # last page is (pages - 1) because the paginator is zero-indexed
|
---|
26 | + if ((page_number + 1) * self.num_per_page) > hits_:
|
---|
27 | + return hits_
|
---|
28 | + else:
|
---|
29 | + return ((page_number + 1) * self.num_per_page)
|
---|
30 | + else: # pages between first and last
|
---|
31 | + return ((page_number + 1) * self.num_per_page)
|
---|
32 |
|
---|
33 | def _get_hits(self):
|
---|
34 | if self._hits is None:
|
---|