Mercurial > piecrust2
diff piecrust/sources/taxonomy.py @ 856:9bb22bbe093c
refactor: Make the blog archives functional again.
The blog archives are using the same pattern as the taxonomy support.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 06 Jun 2017 01:23:25 -0700 |
parents | 448710d84121 |
children | 504ddb370df8 |
line wrap: on
line diff
--- a/piecrust/sources/taxonomy.py Tue Jun 06 00:26:21 2017 -0700 +++ b/piecrust/sources/taxonomy.py Tue Jun 06 01:23:25 2017 -0700 @@ -1,9 +1,6 @@ -import io import re -import time import logging import unidecode -from werkzeug.utils import cached_property from piecrust.configuration import ConfigurationError from piecrust.data.filters import ( PaginationFilter, SettingFilterClause) @@ -14,8 +11,8 @@ ContentPipeline, get_record_name_for_source) from piecrust.pipelines.records import RecordHistory from piecrust.routing import RouteParameter -from piecrust.sources.base import ( - ContentItem, ContentSource, GeneratedContentException) +from piecrust.sources.base import ContentItem +from piecrust.sources.generator import GeneratorSourceBase logger = logging.getLogger(__name__) @@ -57,7 +54,7 @@ """ -class TaxonomySource(ContentSource): +class TaxonomySource(GeneratorSourceBase): """ A content source that generates taxonomy listing pages. """ SOURCE_NAME = 'taxonomy' @@ -66,12 +63,6 @@ def __init__(self, app, name, config): super().__init__(app, name, config) - source_name = config.get('source') - if source_name is None: - raise ConfigurationError( - "Taxonomy source '%s' requires an inner source." % name) - self._inner_source_name = source_name - tax_name = config.get('taxonomy') if tax_name is None: raise ConfigurationError( @@ -84,25 +75,6 @@ tpl_name = config.get('template', '_%s.html' % tax_name) self._raw_item = _taxonomy_index % {'template': tpl_name} - @cached_property - def inner_source(self): - return self.app.getSource(self._inner_source_name) - - def openItem(self, item, mode='r', **kwargs): - return io.StringIO(self._raw_item) - - def getItemMtime(self, item): - return time.time() - - def getContents(self, group): - # Our content is procedurally generated from other content sources, - # so we really don't support listing anything here -- it would be - # quite costly. - # - # Instead, our pipeline (the `TaxonomyPipeline`) will generate - # content items for us when it is asked to produce bake jobs. - raise GeneratedContentException() - def getSupportedRouteParameters(self): name = self.taxonomy.term_name param_type = (RouteParameter.TYPE_PATH if self.taxonomy.is_multiple @@ -321,6 +293,7 @@ page = Page(self.source, job.content_item) prev_entry = ctx.previous_entry cur_entry = result.record_entry + cur_entry.term = content_item.metadata['term'] self._pagebaker.bake(page, prev_entry, cur_entry, []) def postJobRun(self, ctx):