fix: fixed function page_item_count. from calculating: constant * muliplicator * 2. to: constant * multiplicator + constant. first calculation returned wrong amount of items to return
This commit is contained in:
parent
fa8b2b21f9
commit
00a42ea0fd
@ -30,18 +30,20 @@ class PaginationHelper:
|
|||||||
|
|
||||||
return len(
|
return len(
|
||||||
self.collection[
|
self.collection[
|
||||||
self.items_per_page * page_index : self.items_per_page * page_index * 2
|
self.items_per_page * page_index : self.items_per_page * page_index
|
||||||
|
+ self.items_per_page
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
# determines what page an item at the given index is on. Zero based indexes.
|
# determines what page an item at the given index is on. Zero based indexes.
|
||||||
# this method should return -1 for item_index values that are out of range
|
# this method should return -1 for item_index values that are out of range
|
||||||
def page_index(self, item_index):
|
def page_index(self, item_index):
|
||||||
pass
|
try:
|
||||||
|
self.collection[item_index]
|
||||||
|
|
||||||
|
if item_index < 0:
|
||||||
|
raise IndexError
|
||||||
|
except IndexError:
|
||||||
|
return -1
|
||||||
|
|
||||||
collection = ["a", "b", "c", "d", "e", "f"]
|
return item_index // self.items_per_page
|
||||||
helper = PaginationHelper(collection, 4)
|
|
||||||
|
|
||||||
print(helper.page_count())
|
|
||||||
print(helper.page_item_count(1))
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user