diff piecrust/serving/server.py @ 711:ab5c6a8ae90a

bake: Replace hard-coded taxonomy support with "generator" system. * Taxonomies are now implemented one or more `TaxonomyGenerator`s. * A `BlogArchivesGenerator` stub is there but non-functional.
author Ludovic Chabant <ludovic@chabant.com>
date Thu, 26 May 2016 19:52:47 -0700
parents 33ab9badfd7a
children 4850f8c21b6e e053a27e5aae
line wrap: on
line diff
--- a/piecrust/serving/server.py	Thu May 26 19:46:28 2016 -0700
+++ b/piecrust/serving/server.py	Thu May 26 19:52:47 2016 -0700
@@ -183,18 +183,17 @@
         # We have a page, let's try to render it.
         render_ctx = PageRenderingContext(qp,
                                           page_num=req_page.page_num,
-                                          force_render=True)
-        if qp.route.taxonomy_name is not None:
-            taxonomy = app.getTaxonomy(qp.route.taxonomy_name)
-            tax_terms = qp.route.getTaxonomyTerms(qp.route_metadata)
-            render_ctx.setTaxonomyFilter(tax_terms, needs_slugifier=True)
+                                          force_render=True,
+                                          is_from_request=True)
+        if qp.route.is_generator_route:
+            qp.route.generator.prepareRenderContext(render_ctx)
 
         # See if this page is known to use sources. If that's the case,
         # just don't use cached rendered segments for that page (but still
         # use them for pages that are included in it).
         uri = qp.getUri()
         entry = self._page_record.getEntry(uri, req_page.page_num)
-        if (qp.route.taxonomy_name is not None or entry is None or
+        if (qp.route.is_generator_route or entry is None or
                 entry.used_source_names):
             cache_key = '%s:%s' % (uri, req_page.page_num)
             app.env.rendered_segments_repository.invalidate(cache_key)
@@ -202,18 +201,6 @@
         # Render the page.
         rendered_page = render_page(render_ctx)
 
-        # Check if this page is a taxonomy page that actually doesn't match
-        # anything.
-        if qp.route.taxonomy_name is not None:
-            paginator = rendered_page.data.get('pagination')
-            if (paginator and paginator.is_loaded and
-                    len(paginator.items) == 0):
-                taxonomy = app.getTaxonomy(qp.route.taxonomy_name)
-                message = ("This URL matched a route for taxonomy '%s' but "
-                           "no pages have been found to have it. This page "
-                           "won't be generated by a bake." % taxonomy.name)
-                raise NotFound(message)
-
         # Remember stuff for next time.
         if entry is None:
             entry = ServeRecordPageEntry(req_page.req_path, req_page.page_num)