comparison piecrust/rendering.py @ 334:b034f6f15e22

bake: Several bug taxonomy-related fixes for incorrect incremental bakes. * Improve how the baker processes taxonomy terms and figures out what needs to be re-baked or not. * Create bake entries for clean taxnomy terms so they're not deleted by an incremental bake. * Add more information to bake records. * Slugify taxonomy terms is now done by the route in one place. * Fix a bug where the cache key for invalidating rendered segments was not computed the same way as when the caching was done. * Fix how term combinations are passed around, rendered, printed, parsed, etc. (TODO: more word needed in the routing functions) * Expose to the template whether a taxonomy term is a combination or not. * Display term combinations better in the built-in theme. * Rename `route.taxonomy` to `route.taxonomy_name` to prevent confusion. * Add options to show bake records for previous bakes.
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 03 Apr 2015 10:59:50 -0700
parents 422052d2e978
children 938be93215cb
comparison
equal deleted inserted replaced
333:91b07f9efdc1 334:b034f6f15e22
66 66
67 @property 67 @property
68 def source_metadata(self): 68 def source_metadata(self):
69 return self.page.source_metadata 69 return self.page.source_metadata
70 70
71 def reset(self):
72 self.used_pagination = None
73
74 def setPagination(self, paginator): 71 def setPagination(self, paginator):
75 if self.used_pagination is not None: 72 if self.used_pagination is not None:
76 raise Exception("Pagination has already been used.") 73 raise Exception("Pagination has already been used.")
77 self.used_pagination = paginator 74 self.used_pagination = paginator
78 self.addUsedSource(paginator._source) 75 self.addUsedSource(paginator._source)
80 def addUsedSource(self, source): 77 def addUsedSource(self, source):
81 if isinstance(source, PageSource): 78 if isinstance(source, PageSource):
82 self.used_source_names.add((source.name, self.current_pass)) 79 self.used_source_names.add((source.name, self.current_pass))
83 80
84 def setTaxonomyFilter(self, taxonomy, term_value): 81 def setTaxonomyFilter(self, taxonomy, term_value):
82 is_combination = isinstance(term_value, tuple)
85 flt = PaginationFilter(value_accessor=page_value_accessor) 83 flt = PaginationFilter(value_accessor=page_value_accessor)
86 if taxonomy.is_multiple: 84 if taxonomy.is_multiple:
87 if isinstance(term_value, tuple): 85 if is_combination:
88 abc = AndBooleanClause() 86 abc = AndBooleanClause()
89 for t in term_value: 87 for t in term_value:
90 abc.addClause(HasFilterClause(taxonomy.setting_name, t)) 88 abc.addClause(HasFilterClause(taxonomy.setting_name, t))
91 flt.addClause(abc) 89 flt.addClause(abc)
92 else: 90 else:
93 flt.addClause( 91 flt.addClause(
94 HasFilterClause(taxonomy.setting_name, term_value)) 92 HasFilterClause(taxonomy.setting_name, term_value))
95 else: 93 else:
96 flt.addClause(IsFilterClause(taxonomy.setting_name, term_value)) 94 flt.addClause(IsFilterClause(taxonomy.setting_name, term_value))
97 self.pagination_filter = flt 95 self.pagination_filter = flt
96
98 self.custom_data = { 97 self.custom_data = {
99 taxonomy.term_name: term_value} 98 taxonomy.term_name: term_value,
99 'is_multiple_%s' % taxonomy.term_name: is_combination}
100 100
101 101
102 def render_page(ctx): 102 def render_page(ctx):
103 eis = ctx.app.env.exec_info_stack 103 eis = ctx.app.env.exec_info_stack
104 eis.pushPage(ctx.page, ctx) 104 eis.pushPage(ctx.page, ctx)
115 115
116 # Render content segments. 116 # Render content segments.
117 ctx.current_pass = PASS_FORMATTING 117 ctx.current_pass = PASS_FORMATTING
118 repo = ctx.app.env.rendered_segments_repository 118 repo = ctx.app.env.rendered_segments_repository
119 if repo and not ctx.force_render: 119 if repo and not ctx.force_render:
120 cache_key = '%s:%s' % (ctx.uri, ctx.page_num) 120 cache_key = ctx.uri
121 page_time = page.path_mtime 121 page_time = page.path_mtime
122 contents = repo.get( 122 contents = repo.get(
123 cache_key, 123 cache_key,
124 lambda: _do_render_page_segments(page, page_data), 124 lambda: _do_render_page_segments(page, page_data),
125 fs_cache_time=page_time) 125 fs_cache_time=page_time)