comparison piecrust/serving.py @ 363:dd25bd3ce1f9

serve: Refactoring and fixes to be able to serve taxonomy pages. * Page sources' `findPagePath` is renamed to `findPageFactory`, so that it also returns source metadata. * Page refs now store possible hits more properly, and use the previous point to also store metadata. As a result, they can also return a proper factory. * Implement `findPageFactory` correctly in all built-in sources. * When the Chef server matches a taxonomy page, get the source metadata from the page ref in order to make a more proper page. * Make the `getRoute(s)` functions explicitely say if they want taxonomy routes or not.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 26 Apr 2015 15:07:40 -0700
parents 741e97e63048
children 4b1019bb2533
comparison
equal deleted inserted replaced
362:ff595828a364 363:dd25bd3ce1f9
229 taxonomy = None 229 taxonomy = None
230 tax_terms = None 230 tax_terms = None
231 for route, route_metadata in routes: 231 for route, route_metadata in routes:
232 source = app.getSource(route.source_name) 232 source = app.getSource(route.source_name)
233 if route.taxonomy_name is None: 233 if route.taxonomy_name is None:
234 rel_path, fac_metadata = source.findPagePath( 234 factory = source.findPageFactory(route_metadata, MODE_PARSING)
235 route_metadata, MODE_PARSING) 235 if factory is not None:
236 if rel_path is not None:
237 break 236 break
238 else: 237 else:
239 taxonomy = app.getTaxonomy(route.taxonomy_name) 238 taxonomy = app.getTaxonomy(route.taxonomy_name)
240 route_terms = route_metadata.get(taxonomy.term_name) 239 route_terms = route_metadata.get(taxonomy.term_name)
241 if route_terms is not None: 240 if route_terms is not None:
242 tax_page_ref = taxonomy.getPageRef(source.name) 241 tax_page_ref = taxonomy.getPageRef(source.name)
243 rel_path = tax_page_ref.rel_path 242 factory = tax_page_ref.getFactory()
244 source = tax_page_ref.source
245 tax_terms = route.unslugifyTaxonomyTerm(route_terms) 243 tax_terms = route.unslugifyTaxonomyTerm(route_terms)
246 fac_metadata = {taxonomy.term_name: tax_terms} 244 factory.metadata[taxonomy.term_name] = tax_terms
247 break 245 break
248 else: 246 else:
249 raise SourceNotFoundError( 247 raise SourceNotFoundError(
250 "Can't find path for: %s (looked in: %s)" % 248 "Can't find path for: %s (looked in: %s)" %
251 (req_path, [r.source_name for r, _ in routes])) 249 (req_path, [r.source_name for r, _ in routes]))
252 250
253 # Build the page. 251 # Build the page.
254 fac = PageFactory(source, rel_path, fac_metadata) 252 page = factory.buildPage()
255 page = fac.buildPage()
256 # We force the rendering of the page because it could not have 253 # We force the rendering of the page because it could not have
257 # changed, but include pages that did change. 254 # changed, but include pages that did change.
258 render_ctx = PageRenderingContext(page, req_path, page_num, 255 render_ctx = PageRenderingContext(page, req_path, page_num,
259 force_render=True) 256 force_render=True)
260 if taxonomy is not None: 257 if taxonomy is not None: