Skip to content

Commit

Permalink
Pagination functionality
Browse files Browse the repository at this point in the history
- Added pagination to the project report for now

Fixes #57
  • Loading branch information
rerobins committed May 10, 2018
1 parent 3b55a0d commit 5920dae
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
27 changes: 21 additions & 6 deletions autology/reports/project/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from autology.publishing import publish
from autology.reports.models import Report
from autology.utilities.log_file import MetaKeys
from autology.utilities.pagination import pagination

try:
from yaml import CLoader as Loader
Expand Down Expand Up @@ -52,11 +53,24 @@ def _build_report():
orphaned_projects.append(project)

# Sort the logs that are stored on the project
project['log'] = sorted(project.get('log', []), key=lambda x: x.metadata['time'])
project['log'] = sorted(project.get('log', []), key=lambda x: x.metadata['time'], reverse=True)

# Now generate a report for each of the projects.
url = publish('project', 'project', project=project)
project['url'] = url
print('Publishing: {} length: {}'.format(project['id'], len(project['log'])))

pagination_data = pagination(project['log'])

# Publish the first page
print('Publishing: {} pagination data: {} length: {}'.format(project['id'], len(pagination_data), len(project['log'])))

if pagination_data:
publish('project', 'project', project=project, pagination=pagination_data[0])

# Publish the rest of the data
for page_data in pagination_data[1:]:
# Now generate a report for each of the projects.
print('publishing page: {} {}'.format(project['id'], page_data['page_number']))
publish('project', 'project_pagination', project=project, pagination=page_data,
page_number=page_data['page_number'])

main_context = {
'projects': _defined_projects.values(),
Expand All @@ -67,8 +81,9 @@ def _build_report():
if orphaned_projects:
main_context['orphaned_projects'] = orphaned_projects

url = publish('project', 'index', **main_context)
topics.Reporting.REGISTER_REPORT.publish(report=Report('Project', 'List of all project files', ['project', 'index'], {}))
publish('project', 'index', **main_context)
topics.Reporting.REGISTER_REPORT.publish(report=Report('Project', 'List of all project files', ['project', 'index'],
{}))


def process_file(entry):
Expand Down
24 changes: 23 additions & 1 deletion autology/utilities/pagination.py
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

0 comments on commit 5920dae

Please sign in to comment.