-
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.
- Added pagination to the project report for now Fixes #57
- Loading branch information
Showing
2 changed files
with
44 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,29 @@ | ||
"""Module that provides pagination and supporting functionality.""" | ||
|
||
|
||
def pagination(entries, num_entries=15, ): | ||
""" | ||
:param entries: List of all of the entries that need to be paginated (if necessary) | ||
:param num_entries: number of entries that should be provided per page | ||
:return: list of dictionaries that should be passed to the publisher with the appropriate prev and next values | ||
set for the URLs | ||
""" | ||
""" | ||
|
||
# Split the entries into chunks of num_entries size | ||
chunks = [entries[x:x+num_entries] for x in range(0, len(entries), num_entries)] | ||
|
||
# Populate the rest of the data set with values for finding the next pages | ||
return_value = [] | ||
for page_number, page in enumerate(chunks, start=1): | ||
page_data = {'entries': page, | ||
'page_number': page_number} | ||
|
||
if page_number != 1: | ||
page_data['prev_page_number'] = page_number - 1 | ||
|
||
if page_number != len(chunks): | ||
page_data['next_page_number'] = page_number + 1 | ||
|
||
return_value.append(page_data) | ||
|
||
return return_value |