From ded3fad91f45a6df7488f8db579e3b3e91cf1acf Mon Sep 17 00:00:00 2001 From: justin Date: Thu, 27 Sep 2012 21:21:06 -0700 Subject: [PATCH] Avoid index error if there aren't pages when iterating for paginator. --- hyde/ext/plugins/paginator.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/hyde/ext/plugins/paginator.py b/hyde/ext/plugins/paginator.py index 81c417c..1998707 100644 --- a/hyde/ext/plugins/paginator.py +++ b/hyde/ext/plugins/paginator.py @@ -93,20 +93,21 @@ class Paginator: """ added_resources = [] pages = list(self._walk_pages_in_node(node)) - deps = reduce(list.__add__, [page.posts for page in pages], []) - - Paginator._attach_page_to_resource(pages[0], resource) - Paginator._add_dependencies_to_resource(deps, resource) - for page in pages[1:]: - # make new resource - new_resource = self._new_resource(resource, node, page.number) - Paginator._attach_page_to_resource(page, new_resource) - new_resource.depends = resource.depends - added_resources.append(new_resource) - - for prev, next in pairwalk(pages): - next.previous = prev - prev.next = next + if pages: + deps = reduce(list.__add__, [page.posts for page in pages], []) + + Paginator._attach_page_to_resource(pages[0], resource) + Paginator._add_dependencies_to_resource(deps, resource) + for page in pages[1:]: + # make new resource + new_resource = self._new_resource(resource, node, page.number) + Paginator._attach_page_to_resource(page, new_resource) + new_resource.depends = resource.depends + added_resources.append(new_resource) + + for prev, next in pairwalk(pages): + next.previous = prev + prev.next = next return added_resources