Mercurial > piecrust2
comparison piecrust/templating/jinjaengine.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 | d013cc191922 |
children | 1ecc0c16ba64 |
comparison
equal
deleted
inserted
replaced
297:2823ea40cfac | 298:b7ab1b503510 |
---|---|
16 from piecrust.data.paginator import Paginator | 16 from piecrust.data.paginator import Paginator |
17 from piecrust.rendering import format_text | 17 from piecrust.rendering import format_text |
18 from piecrust.routing import CompositeRouteFunction | 18 from piecrust.routing import CompositeRouteFunction |
19 from piecrust.templating.base import (TemplateEngine, TemplateNotFoundError, | 19 from piecrust.templating.base import (TemplateEngine, TemplateNotFoundError, |
20 TemplatingError) | 20 TemplatingError) |
21 from piecrust.uriutil import multi_replace, get_first_sub_uri | 21 from piecrust.uriutil import multi_replace, split_sub_uri |
22 | 22 |
23 | 23 |
24 logger = logging.getLogger(__name__) | 24 logger = logging.getLogger(__name__) |
25 | 25 |
26 | 26 |
174 def _paginate(self, value, items_per_page=5): | 174 def _paginate(self, value, items_per_page=5): |
175 cpi = self.app.env.exec_info_stack.current_page_info | 175 cpi = self.app.env.exec_info_stack.current_page_info |
176 if cpi is None or cpi.page is None or cpi.render_ctx is None: | 176 if cpi is None or cpi.page is None or cpi.render_ctx is None: |
177 raise Exception("Can't paginate when no page has been pushed " | 177 raise Exception("Can't paginate when no page has been pushed " |
178 "on the execution stack.") | 178 "on the execution stack.") |
179 first_uri = get_first_sub_uri(self.app, cpi.render_ctx.uri) | 179 first_uri, _ = split_sub_uri(self.app, cpi.render_ctx.uri) |
180 return Paginator(cpi.page, value, first_uri, | 180 return Paginator(cpi.page, value, first_uri, |
181 page_num=cpi.render_ctx.page_num, | 181 page_num=cpi.render_ctx.page_num, |
182 items_per_page=items_per_page) | 182 items_per_page=items_per_page) |
183 | 183 |
184 def _formatWith(self, value, format_name): | 184 def _formatWith(self, value, format_name): |