comparison piecrust/templating/jinjaengine.py @ 48:002fa58f54dc

Give the proper URL to `Paginator` in the `paginate` filter.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 22 Aug 2014 20:25:41 -0700
parents 1a30e3d7ee47
children e3e3de44377c
comparison
equal deleted inserted replaced
47:558e3602be40 48:002fa58f54dc
11 from pygments.lexers import get_lexer_by_name, guess_lexer 11 from pygments.lexers import get_lexer_by_name, guess_lexer
12 from piecrust.data.paginator import Paginator 12 from piecrust.data.paginator import Paginator
13 from piecrust.rendering import format_text 13 from piecrust.rendering import format_text
14 from piecrust.routing import CompositeRouteFunction 14 from piecrust.routing import CompositeRouteFunction
15 from piecrust.templating.base import TemplateEngine, TemplateNotFoundError 15 from piecrust.templating.base import TemplateEngine, TemplateNotFoundError
16 from piecrust.uriutil import multi_replace 16 from piecrust.uriutil import multi_replace, get_first_sub_uri
17 17
18 18
19 logger = logging.getLogger(__name__) 19 logger = logging.getLogger(__name__)
20 20
21 21
114 def _paginate(self, value, items_per_page=5): 114 def _paginate(self, value, items_per_page=5):
115 cpi = self.app.env.exec_info_stack.current_page_info 115 cpi = self.app.env.exec_info_stack.current_page_info
116 if cpi is None or cpi.page is None or cpi.render_ctx is None: 116 if cpi is None or cpi.page is None or cpi.render_ctx is None:
117 raise Exception("Can't paginate when no page has been pushed " 117 raise Exception("Can't paginate when no page has been pushed "
118 "on the execution stack.") 118 "on the execution stack.")
119 return Paginator(cpi.page, value, cpi.render_ctx.uri, 119 first_uri = get_first_sub_uri(self.app, cpi.render_ctx.uri)
120 return Paginator(cpi.page, value, first_uri,
120 page_num=cpi.render_ctx.page_num, 121 page_num=cpi.render_ctx.page_num,
121 items_per_page=items_per_page) 122 items_per_page=items_per_page)
122 123
123 def _formatWith(self, value, format_name): 124 def _formatWith(self, value, format_name):
124 return format_text(self.app, format_name, value) 125 return format_text(self.app, format_name, value)