Skip to content
Permalink
Browse files

Back to the beginning. But this time with an identity check in _do_cl…

…assification.
  • Loading branch information
felixfontein committed Nov 30, 2016
1 parent 5f14ec8 commit b542321622d438062e8f02c17dadf8c410e83454
Showing with 13 additions and 14 deletions.
  1. +12 −10 nikola/plugins/misc/taxonomies_classifier.py
  2. +1 −4 nikola/plugins/task/taxonomies.py
@@ -44,19 +44,17 @@ class TaxonomiesClassifier(SignalHandler):
name = "render_taxonomies"

def _do_classification(self, site):
# Needed to avoid strange errors during tests
if site is not self.site:
return

# Get list of enabled taxonomy plugins and initialize data structures
taxonomies = site.taxonomy_plugins.values()
site.posts_per_classification = {}
site.taxonomy_plugins = {}
for taxonomy in [p.plugin_object for p in site.plugin_manager.getPluginsOfCategory('Taxonomy')]:
if not taxonomy.is_enabled():
continue
if taxonomy.classification_name in site.taxonomy_plugins:
raise Exception("Found more than one taxonomy with classification name '{}'!".format(taxonomy.classification_name))
site.taxonomy_plugins[taxonomy.classification_name] = taxonomy
for taxonomy in taxonomies:
site.posts_per_classification[taxonomy.classification_name] = {
lang: defaultdict(set) for lang in site.config['TRANSLATIONS'].keys()
}
taxonomies = self.site.taxonomy_plugins.values()

# Classify posts
for post in site.timeline:
@@ -107,7 +105,7 @@ def _do_classification(self, site):
continue
for classification, posts in site.posts_per_classification[taxonomy.classification_name][tlang].items():
# Obtain path as tuple
path = self.site.path_handlers[taxonomy.classification_name](classification, lang)
path = site.path_handlers[taxonomy.classification_name](classification, lang)
# Check that path is OK
for path_element in path:
if len(path_element) == 0:
@@ -315,8 +313,12 @@ def set_site(self, site):
super(TaxonomiesClassifier, self).set_site(site)
# Add hook for after post scanning
blinker.signal("scanned").connect(self._do_classification)
# Register path handlers
# Register path handlers and check for uniqueness of classification name
site.taxonomy_plugins = {}
for taxonomy in [p.plugin_object for p in site.plugin_manager.getPluginsOfCategory('Taxonomy')]:
if not taxonomy.is_enabled():
continue
if taxonomy.classification_name in site.taxonomy_plugins:
raise Exception("Found more than one taxonomy with classification name '{}'!".format(taxonomy.classification_name))
site.taxonomy_plugins[taxonomy.classification_name] = taxonomy
self._register_path_handlers(taxonomy)
@@ -326,10 +326,7 @@ def gen_tasks(self):
self.site.scan_posts()
yield self.group_task()

# for taxonomy in self.site.taxonomy_plugins.values():
for taxonomy in [p.plugin_object for p in self.site.plugin_manager.getPluginsOfCategory('Taxonomy')]:
if not taxonomy.is_enabled():
continue
for taxonomy in self.site.taxonomy_plugins.values():
for lang in self.site.config["TRANSLATIONS"]:
if not taxonomy.is_enabled(lang):
continue

0 comments on commit b542321

Please sign in to comment.
You can’t perform that action at this time.