comparison piecrust/serving.py @ 324:65e6d72f3877

bake/serve: Fix how taxonomy index pages are setup and rendered. * Properly use the taxonomy's setting name where appropriate. * Delete duplicated (and sometimes incorrect) code in 2 places to setup filtering on an index page and consolidate it on the `PageRenderingContext`. * Add unit tests.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 29 Mar 2015 23:08:37 -0700
parents b7ab1b503510
children de4903457bed
comparison
equal deleted inserted replaced
323:412537e91e45 324:65e6d72f3877
14 NotFound, MethodNotAllowed, InternalServerError, HTTPException) 14 NotFound, MethodNotAllowed, InternalServerError, HTTPException)
15 from werkzeug.wrappers import Request, Response 15 from werkzeug.wrappers import Request, Response
16 from werkzeug.wsgi import ClosingIterator, wrap_file 16 from werkzeug.wsgi import ClosingIterator, wrap_file
17 from jinja2 import FileSystemLoader, Environment 17 from jinja2 import FileSystemLoader, Environment
18 from piecrust.app import PieCrust 18 from piecrust.app import PieCrust
19 from piecrust.data.filters import (
20 PaginationFilter, HasFilterClause, IsFilterClause,
21 page_value_accessor)
22 from piecrust.environment import StandardEnvironment 19 from piecrust.environment import StandardEnvironment
23 from piecrust.processing.base import ProcessorPipeline 20 from piecrust.processing.base import ProcessorPipeline
24 from piecrust.rendering import PageRenderingContext, render_page 21 from piecrust.rendering import PageRenderingContext, render_page
25 from piecrust.sources.base import PageFactory, MODE_PARSING 22 from piecrust.sources.base import PageFactory, MODE_PARSING
26 from piecrust.uriutil import split_sub_uri 23 from piecrust.uriutil import split_sub_uri
228 routes = find_routes(app.routes, req_path) 225 routes = find_routes(app.routes, req_path)
229 if len(routes) == 0: 226 if len(routes) == 0:
230 raise RouteNotFoundError("Can't find route for: %s" % req_path) 227 raise RouteNotFoundError("Can't find route for: %s" % req_path)
231 228
232 taxonomy = None 229 taxonomy = None
230 term_value = None
233 for route, route_metadata in routes: 231 for route, route_metadata in routes:
234 source = app.getSource(route.source_name) 232 source = app.getSource(route.source_name)
235 if route.taxonomy is None: 233 if route.taxonomy is None:
236 rel_path, fac_metadata = source.findPagePath( 234 rel_path, fac_metadata = source.findPagePath(
237 route_metadata, MODE_PARSING) 235 route_metadata, MODE_PARSING)
257 # We force the rendering of the page because it could not have 255 # We force the rendering of the page because it could not have
258 # changed, but include pages that did change. 256 # changed, but include pages that did change.
259 render_ctx = PageRenderingContext(page, req_path, page_num, 257 render_ctx = PageRenderingContext(page, req_path, page_num,
260 force_render=True) 258 force_render=True)
261 if taxonomy is not None: 259 if taxonomy is not None:
262 flt = PaginationFilter(value_accessor=page_value_accessor) 260 render_ctx.setTaxonomyFilter(taxonomy, term_value)
263 if taxonomy.is_multiple:
264 flt.addClause(HasFilterClause(taxonomy.name, term_value))
265 else:
266 flt.addClause(IsFilterClause(taxonomy.name, term_value))
267 render_ctx.pagination_filter = flt
268 render_ctx.custom_data = {
269 taxonomy.term_name: term_value}
270 261
271 # See if this page is known to use sources. If that's the case, 262 # See if this page is known to use sources. If that's the case,
272 # just don't use cached rendered segments for that page (but still 263 # just don't use cached rendered segments for that page (but still
273 # use them for pages that are included in it). 264 # use them for pages that are included in it).
274 entry = self._page_record.getEntry(req_path, page_num) 265 entry = self._page_record.getEntry(req_path, page_num)