comparison piecrust/rendering.py @ 991:1857dbd4580f

bake: Fix bugs introduced by bake optimizations, of course. - Make the execution stats JSON-serializable. - Re-add ability to differentiate between sources used during segment rendering and during layout rendering. Fixes problems with cache invalidation of pages that use other sources. - Make taxonomy-related stuff JSON-serializable.
author Ludovic Chabant <ludovic@chabant.com>
date Mon, 20 Nov 2017 23:06:47 -0800
parents 8adc27285d93
children e94737572542
comparison
equal deleted inserted replaced
990:22cf13b86cc3 991:1857dbd4580f
50 """ Creates a bag of rendering properties. It's a dictionary because 50 """ Creates a bag of rendering properties. It's a dictionary because
51 it will be passed between workers during the bake process, and 51 it will be passed between workers during the bake process, and
52 saved to records. 52 saved to records.
53 """ 53 """
54 return { 54 return {
55 'used_source_names': set(), 55 'used_source_names': {'segments': [], 'layout': []},
56 'used_pagination': False, 56 'used_pagination': False,
57 'pagination_has_more': False, 57 'pagination_has_more': False,
58 'used_assets': False, 58 'used_assets': False,
59 } 59 }
60 60
66 self.force_render = force_render 66 self.force_render = force_render
67 self.pagination_source = None 67 self.pagination_source = None
68 self.pagination_filter = None 68 self.pagination_filter = None
69 self.render_info = create_render_info() 69 self.render_info = create_render_info()
70 self.custom_data = {} 70 self.custom_data = {}
71 self._current_used_source_names = None
71 72
72 @property 73 @property
73 def app(self): 74 def app(self):
74 return self.page.app 75 return self.page.app
76
77 @property
78 def current_used_source_names(self):
79 usn = self._current_used_source_names
80 if usn is not None:
81 return usn
82 else:
83 raise Exception("No render pass specified.")
84
85 def setRenderPass(self, name):
86 if name is not None:
87 self._current_used_source_names = \
88 self.render_info['used_source_names'][name]
89 else:
90 self._current_used_source_names = None
75 91
76 def setPagination(self, paginator): 92 def setPagination(self, paginator):
77 ri = self.render_info 93 ri = self.render_info
78 if ri.get('used_pagination'): 94 if ri.get('used_pagination'):
79 raise Exception("Pagination has already been used.") 95 raise Exception("Pagination has already been used.")
81 ri['used_pagination'] = True 97 ri['used_pagination'] = True
82 ri['pagination_has_more'] = paginator.has_more 98 ri['pagination_has_more'] = paginator.has_more
83 self.addUsedSource(paginator._source) 99 self.addUsedSource(paginator._source)
84 100
85 def addUsedSource(self, source): 101 def addUsedSource(self, source):
86 ri = self.render_info 102 usn = self.current_used_source_names
87 ri['used_source_names'].add(source.name) 103 if source.name not in usn:
104 usn.append(source.name)
88 105
89 106
90 class RenderingContextStack(object): 107 class RenderingContextStack(object):
91 def __init__(self): 108 def __init__(self):
92 self._ctx_stack = [] 109 self._ctx_stack = []
251 268
252 def _do_render_page_segments(ctx, page_data): 269 def _do_render_page_segments(ctx, page_data):
253 page = ctx.page 270 page = ctx.page
254 app = page.app 271 app = page.app
255 272
273 ctx.setRenderPass('segments')
274
256 engine_name = page.config.get('template_engine') 275 engine_name = page.config.get('template_engine')
257 format_name = page.config.get('format') 276 format_name = page.config.get('format')
258 277
259 engine = get_template_engine(app, engine_name) 278 engine = get_template_engine(app, engine_name)
260 279
294 app = page.app 313 app = page.app
295 cur_ctx = app.env.render_ctx_stack.current_ctx 314 cur_ctx = app.env.render_ctx_stack.current_ctx
296 assert cur_ctx is not None 315 assert cur_ctx is not None
297 assert cur_ctx.page == page 316 assert cur_ctx.page == page
298 317
318 cur_ctx.setRenderPass('layout')
319
299 names = layout_name.split(',') 320 names = layout_name.split(',')
300 full_names = [] 321 full_names = []
301 for name in names: 322 for name in names:
302 if '.' not in name: 323 if '.' not in name:
303 full_names.append(name + '.html') 324 full_names.append(name + '.html')