comparison piecrust/sources/taxonomy.py @ 979:45ad976712ec

tests: Big push to get the tests to pass again. - Lots of fixes everywhere in the code. - Try to handle debug logging in the multiprocessing worker pool when running in pytest. Not perfect, but usable for now. - Replace all `.md` test files with `.html` since now a auto-format extension always sets the format. - Replace `out` with `outfiles` in most places since now blog archives are added to the bake output and I don't want to add expected outputs for blog archives everywhere.
author Ludovic Chabant <ludovic@chabant.com>
date Sun, 29 Oct 2017 22:51:57 -0700
parents 85d2b386b971
children 8adc27285d93
comparison
equal deleted inserted replaced
978:7e51d14097cb 979:45ad976712ec
159 self.taxonomy, self.slugifier.mode, term_value, is_combination)) 159 self.taxonomy, self.slugifier.mode, term_value, is_combination))
160 ctx.pagination_filter = flt 160 ctx.pagination_filter = flt
161 161
162 def onRouteFunctionUsed(self, route_params): 162 def onRouteFunctionUsed(self, route_params):
163 # Get the values, and slugify them appropriately. 163 # Get the values, and slugify them appropriately.
164 # If this is a "multiple" taxonomy, `values` will be a tuple of
165 # terms. If not, `values` will just be a term.
164 values = route_params[self.taxonomy.term_name] 166 values = route_params[self.taxonomy.term_name]
165 if self.taxonomy.is_multiple: 167 tax_is_multiple = self.taxonomy.is_multiple
166 # TODO: here we assume the route has been properly configured. 168 if tax_is_multiple:
167 slugified_values = self.slugifyMultiple((str(v) for v in values)) 169 slugified_values = self.slugifyMultiple((str(v) for v in values))
168 route_val = self.taxonomy.separator.join(slugified_values) 170 route_val = self.taxonomy.separator.join(slugified_values)
169 else: 171 else:
170 slugified_values = self.slugify(str(values)) 172 slugified_values = self.slugify(str(values))
171 route_val = slugified_values 173 route_val = slugified_values
172 174
173 # We need to register this use of a taxonomy term. 175 # We need to register this use of a taxonomy term.
174 rcs = self.app.env.render_ctx_stack 176 rcs = self.app.env.render_ctx_stack
175 cpi = rcs.current_ctx.current_pass_info 177 cpi = rcs.current_ctx.current_pass_info
176 if cpi: 178 if cpi:
177 utt = cpi.getCustomInfo('used_taxonomy_terms', [], True) 179 utt = cpi.getCustomInfo('used_taxonomy_terms')
178 utt.append(slugified_values) 180 if utt is None:
181 utt = set()
182 utt.add(slugified_values)
183 cpi.setCustomInfo('used_taxonomy_terms', utt)
184 else:
185 utt.add(slugified_values)
179 186
180 # Put the slugified values in the route metadata so they're used to 187 # Put the slugified values in the route metadata so they're used to
181 # generate the URL. 188 # generate the URL.
182 route_params[self.taxonomy.term_name] = route_val 189 route_params[self.taxonomy.term_name] = route_val
183 190
405 # combinations, so that we have less things to test further down the 412 # combinations, so that we have less things to test further down the
406 # line. 413 # line.
407 # 414 #
408 # Add the combinations to that list. We get those combinations from 415 # Add the combinations to that list. We get those combinations from
409 # wherever combinations were used, so they're coming from the 416 # wherever combinations were used, so they're coming from the
410 # `onRouteFunctionUsed` method. 417 # `onRouteFunctionUsed` method. And because combinations can be used
418 # by any page in the website (anywhere someone can ask for an URL
419 # to the combination page), it means we check all the records, not
420 # just the record for our source.
411 if taxonomy.is_multiple: 421 if taxonomy.is_multiple:
412 known_combinations = set() 422 known_combinations = set()
413 for cur_entry in cur_rec.getEntries(): 423 for rec in current_records.records:
414 used_terms = _get_all_entry_taxonomy_terms(cur_entry) 424 # Cheap way to test if a record contains entries that
415 for terms in used_terms: 425 # are sub-types of a page entry: test the first one.
416 if len(terms) > 1: 426 first_entry = next(iter(rec.getEntries()), None)
417 known_combinations.add(terms) 427 if (first_entry is None or
428 not isinstance(first_entry, PagePipelineRecordEntry)):
429 continue
430
431 for cur_entry in rec.getEntries():
432 used_terms = _get_all_entry_taxonomy_terms(cur_entry)
433 for terms in used_terms:
434 if len(terms) > 1:
435 known_combinations.add(terms)
418 436
419 dcc = 0 437 dcc = 0
420 for terms in known_combinations: 438 for terms in known_combinations:
421 if not self._single_dirty_slugified_terms.isdisjoint( 439 if not self._single_dirty_slugified_terms.isdisjoint(
422 set(terms)): 440 set(terms)):