comparison piecrust/sources/taxonomy.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 5f97b5b59dfe
comparison
equal deleted inserted replaced
990:22cf13b86cc3 991:1857dbd4580f
173 else: 173 else:
174 slugified_values = self.slugify(str(values)) 174 slugified_values = self.slugify(str(values))
175 route_val = slugified_values 175 route_val = slugified_values
176 176
177 # We need to register this use of a taxonomy term. 177 # We need to register this use of a taxonomy term.
178 # Because the render info gets serialized across bake worker
179 # processes, we can only use basic JSON-able structures, which
180 # excludes `set`... hence the awkward use of `list`.
181 # Also, note that the tuples we're putting in there will be
182 # transformed into lists so we'll have to convert back.
178 rcs = self.app.env.render_ctx_stack 183 rcs = self.app.env.render_ctx_stack
179 ri = rcs.current_ctx.render_info 184 ri = rcs.current_ctx.render_info
180 utt = ri.get('used_taxonomy_terms') 185 utt = ri.get('used_taxonomy_terms')
181 if utt is None: 186 if utt is None:
182 utt = set() 187 ri['used_taxonomy_terms'] = [slugified_values]
183 utt.add(slugified_values)
184 ri['used_taxonomy_terms'] = utt
185 else: 188 else:
186 utt.add(slugified_values) 189 if slugified_values not in utt:
190 utt.append(slugified_values)
187 191
188 # Put the slugified values in the route metadata so they're used to 192 # Put the slugified values in the route metadata so they're used to
189 # generate the URL. 193 # generate the URL.
190 route_params[self.taxonomy.term_name] = route_val 194 route_params[self.taxonomy.term_name] = route_val
191 195
479 res = set() 483 res = set()
480 for o in entry.subs: 484 for o in entry.subs:
481 pinfo = o['render_info'] 485 pinfo = o['render_info']
482 terms = pinfo.get('used_taxonomy_terms') 486 terms = pinfo.get('used_taxonomy_terms')
483 if terms: 487 if terms:
484 res |= set(terms) 488 res |= set([tuple(t) for t in terms])
485 return res 489 return res
486 490
487 491
488 class _Slugifier(object): 492 class _Slugifier(object):
489 def __init__(self, taxonomy, mode): 493 def __init__(self, taxonomy, mode):