Mercurial > piecrust2
comparison piecrust/dataproviders/pageiterator.py @ 1153:a9a592f655e3
config: Add setting for enabling baking or serving posts in the future.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 19 Jan 2019 17:41:30 -0800 |
parents | d4e0c53aa6e8 |
children |
comparison
equal
deleted
inserted
replaced
1152:74c0c7483986 | 1153:a9a592f655e3 |
---|---|
264 if app.config.get('baker/is_baking'): | 264 if app.config.get('baker/is_baking'): |
265 # While baking, automatically exclude any page with | 265 # While baking, automatically exclude any page with |
266 # the `draft` setting. | 266 # the `draft` setting. |
267 draft_setting = app.config['baker/no_bake_setting'] | 267 draft_setting = app.config['baker/no_bake_setting'] |
268 self._it = NoDraftsIterator(self._it, draft_setting) | 268 self._it = NoDraftsIterator(self._it, draft_setting) |
269 | |
270 if not app.config.get('baker/bake_future'): | |
271 # Don't bake pages from the future. | |
272 self._it = PruneFutureIterator(self._it, | |
273 app.env.start_datetime) | |
274 elif app.config.get('server/is_serving'): | |
275 if not app.config.get('server/serve_future'): | |
276 # Don't serve pages from the future. | |
277 self._it = PruneFutureIterator(self._it, | |
278 app.env.start_datetime) | |
269 else: | 279 else: |
270 self._it = GenericSourceIterator(self._source) | 280 self._it = GenericSourceIterator(self._source) |
271 | 281 |
272 def _unload(self): | 282 def _unload(self): |
273 self._initIterator() | 283 self._initIterator() |
423 def __iter__(self): | 433 def __iter__(self): |
424 nds = self.no_draft_setting | 434 nds = self.no_draft_setting |
425 yield from filter(lambda i: not i.config.get(nds), self.it) | 435 yield from filter(lambda i: not i.config.get(nds), self.it) |
426 | 436 |
427 | 437 |
438 class PruneFutureIterator: | |
439 def __init__(self, source, now_dt): | |
440 self.it = source | |
441 self.now_dt = now_dt | |
442 | |
443 def __iter__(self): | |
444 now_dt = self.now_dt | |
445 for i in self.it: | |
446 if i.datetime <= now_dt: | |
447 yield i | |
448 | |
428 class PaginationDataBuilderIterator: | 449 class PaginationDataBuilderIterator: |
429 def __init__(self, it): | 450 def __init__(self, it): |
430 self.it = it | 451 self.it = it |
431 | 452 |
432 def __iter__(self): | 453 def __iter__(self): |