Skip to content

Commit

Permalink
Back to the beginning. But this time with an identity check in _do_cl…
Browse files Browse the repository at this point in the history
…assification.
  • Loading branch information
felixfontein committed Nov 30, 2016
1 parent 5f14ec8 commit b542321
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
22 changes: 12 additions & 10 deletions nikola/plugins/misc/taxonomies_classifier.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
5 changes: 1 addition & 4 deletions nikola/plugins/task/taxonomies.py
Expand Up @@ -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
Expand Down

0 comments on commit b542321

Please sign in to comment.