Mercurial > piecrust2
comparison piecrust/dataproviders/blog.py @ 1033:57283302b3ee
data: Fix a bug when listing a blog's posts twice on a page.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 16 Jan 2018 08:38:46 -0800 |
parents | 492b66482f12 |
children | d464c1b1d686 |
comparison
equal
deleted
inserted
replaced
1032:54159951d97a | 1033:57283302b3ee |
---|---|
28 "combining multiple sources.") | 28 "combining multiple sources.") |
29 | 29 |
30 @property | 30 @property |
31 def posts(self): | 31 def posts(self): |
32 self._buildPosts() | 32 self._buildPosts() |
33 # Reset each time on access in case a page is showing 2 different | |
34 # lists of the same blog. | |
35 self._posts.reset() | |
33 return self._posts | 36 return self._posts |
34 | 37 |
35 @property | 38 @property |
36 def years(self): | 39 def years(self): |
37 self._buildArchives() | 40 self._buildArchives() |
68 return list(self._app.config.get('site/taxonomies').keys()) | 71 return list(self._app.config.get('site/taxonomies').keys()) |
69 | 72 |
70 def _buildPosts(self): | 73 def _buildPosts(self): |
71 if self._posts is None: | 74 if self._posts is None: |
72 it = PageIterator(self._sources[0], current_page=self._page) | 75 it = PageIterator(self._sources[0], current_page=self._page) |
73 it._load_event += self._onIteration | 76 self._onIteration() |
74 self._posts = it | 77 self._posts = it |
75 | 78 |
76 def _buildArchives(self): | 79 def _buildArchives(self): |
77 if self._archives_built: | 80 if self._archives_built: |
78 return | 81 return |
146 self._taxonomies = {} | 149 self._taxonomies = {} |
147 for tax_name, entries in tax_index.items(): | 150 for tax_name, entries in tax_index.items(): |
148 self._taxonomies[tax_name] = list( | 151 self._taxonomies[tax_name] = list( |
149 sorted(entries.values(), key=lambda i: i.term)) | 152 sorted(entries.values(), key=lambda i: i.term)) |
150 | 153 |
151 self._onIteration(None) | 154 self._onIteration() |
152 | 155 |
153 self._archives_built = True | 156 self._archives_built = True |
154 | 157 |
155 def _onIteration(self, it): | 158 def _onIteration(self): |
156 if not self._ctx_set: | 159 if not self._ctx_set: |
157 rcs = self._app.env.render_ctx_stack | 160 rcs = self._app.env.render_ctx_stack |
158 if rcs.current_ctx: | 161 if rcs.current_ctx: |
159 rcs.current_ctx.addUsedSource(self._sources[0]) | 162 rcs.current_ctx.addUsedSource(self._sources[0]) |
160 self._ctx_set = True | 163 self._ctx_set = True |