comparison piecrust/serving.py @ 298:b7ab1b503510

data: Fix incorrect next/previous page URLs in pagination data. Consolidate splitting an URL between its first URL and its sub page number. Be careful about the index page's URL not losing its slash.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 11 Mar 2015 23:46:42 -0700
parents 8c0c53a315ae
children 65e6d72f3877
comparison
equal deleted inserted replaced
297:2823ea40cfac 298:b7ab1b503510
21 page_value_accessor) 21 page_value_accessor)
22 from piecrust.environment import StandardEnvironment 22 from piecrust.environment import StandardEnvironment
23 from piecrust.processing.base import ProcessorPipeline 23 from piecrust.processing.base import ProcessorPipeline
24 from piecrust.rendering import PageRenderingContext, render_page 24 from piecrust.rendering import PageRenderingContext, render_page
25 from piecrust.sources.base import PageFactory, MODE_PARSING 25 from piecrust.sources.base import PageFactory, MODE_PARSING
26 from piecrust.uriutil import split_sub_uri
26 27
27 28
28 logger = logging.getLogger(__name__) 29 logger = logging.getLogger(__name__)
29 30
30 31
220 221
221 return self._make_wrapped_file_response(environ, request, full_path) 222 return self._make_wrapped_file_response(environ, request, full_path)
222 223
223 def _try_serve_page(self, app, environ, request): 224 def _try_serve_page(self, app, environ, request):
224 # Try to find what matches the requested URL. 225 # Try to find what matches the requested URL.
225 req_path = request.path 226 req_path, page_num = split_sub_uri(app, request.path)
226 page_num = 1
227 pgn_suffix_re = app.config.get('__cache/pagination_suffix_re')
228 pgn_suffix_m = re.search(pgn_suffix_re, request.path)
229 if pgn_suffix_m:
230 req_path = request.path[:pgn_suffix_m.start()]
231 page_num = int(pgn_suffix_m.group('num'))
232 227
233 routes = find_routes(app.routes, req_path) 228 routes = find_routes(app.routes, req_path)
234 if len(routes) == 0: 229 if len(routes) == 0:
235 raise RouteNotFoundError("Can't find route for: %s" % req_path) 230 raise RouteNotFoundError("Can't find route for: %s" % req_path)
236 231