Mercurial > piecrust2
view piecrust/taxonomies.py @ 242:f130365568ff
internal: Code reorganization to put less stuff in `sources.base`.
Interfaces that sources can implement are in `sources.interfaces`. The default
page source is in `sources.default`. The `SimplePageSource` is gone since most
subclasses only wanted to do *some* stuff the same, but *lots* of stuff
slightly different. I may have to revisit the code to extract exactly the code
that's in common.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 18 Feb 2015 18:35:03 -0800 |
parents | f485ba500df3 |
children | 6c5de6edacf7 |
line wrap: on
line source
from piecrust.sources.pageref import PageRef, PageNotFoundError class Taxonomy(object): def __init__(self, app, name, config): self.app = app self.name = name self.term_name = config['term'] self.is_multiple = config['multiple'] self.page_ref = config['page'] self._source_page_refs = {} def resolvePagePath(self, source_name): pr = self.getPageRef(source_name) try: return pr.path except PageNotFoundError: return None def getPageRef(self, source_name): if source_name in self._source_page_refs: return self._source_page_refs[source_name] source = self.app.getSource(source_name) ref_path = (source.getTaxonomyPageRef(self.name) or '%s:%s' % (source_name, self.page_ref)) page_ref = PageRef(self.app, ref_path) self._source_page_refs[source_name] = page_ref return page_ref