Mercurial > piecrust2
comparison piecrust/data/iterators.py @ 729:e35407c60e00
templating: Make blog archives generator expose more templating data.
In addition to pagination data, also expose a non-paginating iterator that
lists all posts in a source by chronological order.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 01 Jun 2016 22:09:21 -0700 |
parents | 911a054f4fbd |
children | 4850f8c21b6e |
comparison
equal
deleted
inserted
replaced
728:e7481bbbb29f | 729:e35407c60e00 |
---|---|
107 for page in self.it: | 107 for page in self.it: |
108 if self._fil.pageMatches(page): | 108 if self._fil.pageMatches(page): |
109 yield page | 109 yield page |
110 | 110 |
111 | 111 |
112 class GenericSortIterator(object): | |
113 def __init__(self, it, sorter): | |
114 self.it = it | |
115 self.sorter = sorter | |
116 self._sorted_it = None | |
117 | |
118 def __iter__(self): | |
119 if self._sorted_it is None: | |
120 self._sorted_it = self.sorter(self.it) | |
121 return iter(self._sorted_it) | |
122 | |
123 | |
112 class PageIterator(object): | 124 class PageIterator(object): |
113 debug_render = [] | 125 debug_render = [] |
114 debug_render_doc_dynamic = ['_debugRenderDoc'] | 126 debug_render_doc_dynamic = ['_debugRenderDoc'] |
115 debug_render_not_empty = True | 127 debug_render_not_empty = True |
116 | 128 |
117 def __init__(self, source, current_page=None, pagination_filter=None, | 129 def __init__(self, source, *, |
118 offset=0, limit=-1, locked=False): | 130 current_page=None, |
131 pagination_filter=None, sorter=None, | |
132 offset=0, limit=-1, locked=False): | |
119 self._source = source | 133 self._source = source |
120 self._current_page = current_page | 134 self._current_page = current_page |
121 self._locked = False | 135 self._locked = False |
122 self._pages = source | 136 self._pages = source |
123 self._pagesData = None | 137 self._pagesData = None |
149 # Apply any filter first, before we start sorting or slicing. | 163 # Apply any filter first, before we start sorting or slicing. |
150 if pagination_filter is not None: | 164 if pagination_filter is not None: |
151 self._simpleNonSortedWrap(PaginationFilterIterator, | 165 self._simpleNonSortedWrap(PaginationFilterIterator, |
152 pagination_filter) | 166 pagination_filter) |
153 | 167 |
168 if sorter is not None: | |
169 self._simpleNonSortedWrap(GenericSortIterator, sorter) | |
170 self._has_sorter = True | |
171 | |
154 if offset > 0 or limit > 0: | 172 if offset > 0 or limit > 0: |
155 self.slice(offset, limit) | 173 self.slice(offset, limit) |
156 | 174 |
157 self._locked = locked | 175 self._locked = locked |
158 | 176 |