-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dc6a2c5
commit 7e18cae
Showing
24 changed files
with
505 additions
and
305 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from math import ceil | ||
|
||
class Pagination: | ||
def __init__(self, page, per_page, total_count): | ||
self.page = page | ||
self.per_page = per_page | ||
self.total_count = total_count | ||
|
||
@property | ||
def pages(self): | ||
return int(ceil(self.total_count / float(self.per_page))) | ||
|
||
@property | ||
def has_prev(self): | ||
return self.page > 1 | ||
|
||
@property | ||
def has_next(self): | ||
return self.page < self.pages | ||
|
||
|
||
@property | ||
def next_num(self): | ||
return self.page + 1 | ||
|
||
@property | ||
def prev_num(self): | ||
return self.page - 1 | ||
|
||
|
||
def iter_pages(self, left_edge=2, left_current=2, | ||
right_current=5, right_edge=2): | ||
last = 0 | ||
for num in range(1, self.pages + 1): | ||
if num <= left_edge or \ | ||
(num > self.page - left_current - 1 and \ | ||
num < self.page + right_current) or \ | ||
num > self.pages - right_edge: | ||
if last + 1 != num: | ||
yield None | ||
yield num | ||
last = num | ||
|
||
def iter_pages_back(self, left_edge=2, left_current=2, | ||
right_current=5, right_edge=2): | ||
last = 0 | ||
for num in range(self.pages, 0, -1): | ||
if num <= left_edge or \ | ||
(num > self.page - left_current - 1 and \ | ||
num < self.page + right_current) or \ | ||
num > self.pages - right_edge: | ||
if last + 1 != num: | ||
yield None | ||
yield num | ||
last = num | ||
|
||
def iter_pages_back_with_first(self, left_edge=2, left_current=2, | ||
right_current=5, right_edge=2): | ||
last = 0 | ||
for num in range(self.pages, 0, -1): | ||
if num <= left_edge or \ | ||
(num > self.page - left_current - 1 and \ | ||
num < self.page + right_current) or \ | ||
num > self.pages - right_edge: | ||
if last + 1 != num: | ||
yield None | ||
yield num | ||
last = num | ||
yield 1 | ||
|
||
|
Oops, something went wrong.