Skip to content

Commit 8a69513

Browse files
committedJan 6, 2017
Simplifying fake hierarchy creation.
1 parent a491cea commit 8a69513

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed
 

‎v7/sidebar/sidebar.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,23 @@ def invert_order(node):
101101
flat_hierarchy = utils.flatten_tree_structure(root_list)
102102
else:
103103
flat_hierarchy = self.site.flat_hierarchy_per_classification[taxonomy_name][lang]
104-
# Build flattened hierarchy list
105-
hierarchy = [(taxonomy.get_classification_friendly_name(node.classification_name, lang, only_last_component=False),
106-
node.classification_name, node.classification_path,
107-
self.site.link(taxonomy_name, node.classification_name, lang),
108-
node.indent_levels, node.indent_change_before,
109-
node.indent_change_after,
110-
len(node.children),
111-
len([post for post in posts_per_tag[node.classification_name] if acceptor(post)]))
112-
for node in flat_hierarchy]
113104
else:
114-
# Fake hierarchy
115-
hierarchy = [(classification_name, classification, taxonomy.extract_hierarchy(classification),
116-
self.site.link(taxonomy_name, classification, lang),
117-
(i, len(result)), 1 if i == 0 else 0, -1 if i == len(result) - 1 else 0, 0,
118-
count)
119-
for i, ((_, count, link), (classification_name, classification)) in enumerate(zip(result, classifications))]
105+
root_list = []
106+
for classification_name, classification in classifications:
107+
node = utils.TreeNode('')
108+
node.classification_name = classification_name
109+
node.classification_path = taxonomy.extract_hierarchy(classification)
110+
root_list.append(node)
111+
flat_hierarchy = utils.flatten_tree_structure(root_list)
112+
# Build flattened hierarchy list
113+
hierarchy = [(taxonomy.get_classification_friendly_name(node.classification_name, lang, only_last_component=False),
114+
node.classification_name, node.classification_path,
115+
self.site.link(taxonomy_name, node.classification_name, lang),
116+
node.indent_levels, node.indent_change_before,
117+
node.indent_change_after,
118+
len(node.children),
119+
len([post for post in posts_per_tag[node.classification_name] if acceptor(post)]))
120+
for node in flat_hierarchy]
120121
return result, hierarchy
121122
else:
122123
return None, None

0 commit comments

Comments
 (0)
Please sign in to comment.