Commit 8f3e1a32 authored by Denis Salem's avatar Denis Salem
Browse files

fix couple of thing, done with blog/entry categories leaves

parent e7eb382d
......@@ -138,6 +138,7 @@
TODO | Split install and blog creation chapter in tutorial.
TODO | fix FAQ https://stackoverflow.com/questions/14547631/python-locale-error-unsupported-locale-setting.
TODO | fix FAQ latex2mathml is incomplete.
TODO | fix FAQ categories separator is ' > ', not '>'
TODO | Change nomenclature: Most of the usual patterns are changed. Fix doc.
TODO | Add translation for Deutsch and Spanish.
......@@ -145,3 +146,4 @@
TODO | Add docutils reStructuredText parser settings override.
TODO | Decrease halt_level to render reStructuredText even if errors occurs.
TODO | Access {count} and {weight} from LeavesForEntrycategories.
......@@ -86,6 +86,7 @@ non_contextual_pattern_names_blog = {
# Extra metadata getter
"GetBlogMetadataIfExists" : "get_blog_metadata_if_exists",
"ForBlogDates" : "for_blog_dates",
"LeavesForBlogCategories" : "leaves_for_blog_categories",
"TreeForBlogCategories" : "tree_for_blog_categories"
}
......
......@@ -24,7 +24,7 @@ from venc2.datastore.metadata import build_categories_tree
from venc2.datastore.metadata import MetadataNode
def merge(iterable, argv):
return argv[1].join(
return ''.join(
[
argv[0].format(**something) for something in iterable
]
......@@ -39,6 +39,7 @@ class DataStore:
self.entries_per_categories = list()
self.requested_entry_index = 0
self.max_category_weight = 1
self.categories_leaves = []
self.html_categories_tree = None
''' Entry index is different from entry id '''
......@@ -63,7 +64,7 @@ class DataStore:
''' Update entriesPerCategories '''
build_categories_tree(entry_index, self.entries[-1].raw_categories, self.entries_per_categories, self.max_category_weight, self.set_max_category_weight)
build_categories_tree(entry_index, self.entries[-1].raw_categories, self.entries_per_categories, self.categories_leaves, self.max_category_weight, self.set_max_category_weight)
entry_index += 1
''' Setup BlogDates Data '''
......@@ -197,6 +198,7 @@ class DataStore:
dates = [o for o in self.blog_dates if o["date"] not in self.disable_threads]
return merge(dates, argv)
def build_html_categories_tree(self, opening_node, opening_branch, closing_branch, closing_node, tree):
output_string = opening_node
for node in sorted(tree, key = lambda x : x.value):
......@@ -259,8 +261,22 @@ class DataStore:
def for_entry_authors(self, argv):
return merge(self.entries[self.requested_entry_index].authors, argv)
""" TODO in 2.x.x: Access {count} and {weight} from LeavesForEntrycategories by taking benefit of preprocessing. """
def leaves_for_entry_categories(self, argv):
return merge(self.entries[self.requested_entry_index].categories_leaves, argv)
def leaves_for_blog_categories(self, argv):
items = []
for node in self.categories_leaves:
items.append({
"item" : node.value,
"count" : node.count,
"weight" : round(node.weight / self.max_category_weight,2),
"path" : node.path
})
return merge(items, argv)
......
......@@ -134,7 +134,7 @@ class Entry:
pass
self.categories_tree = []
build_categories_tree(-1, self.raw_categories, self.categories_tree, -1)
build_categories_tree(-1, self.raw_categories, self.categories_tree, None, -1)
self.html_categories_tree = None
''' Iterate through entries folder '''
......
......@@ -28,26 +28,13 @@ class MetadataNode:
self.related_to = [entry_index]
self.childs = list()
def build_categories_leaves():
try:
for category in self.raw_categories:
category_leaf = category.split(' > ')[-1].strip()
if len(category_leaf) != 0:
category_leaf_url = str()
for sub_category in category.split(' > '):
category_leaf_url +=sub_category.strip()+'/'
self.categories_leaves.append({
"categoryLeaf": category_leaf,
"categoryLeafPath":category_leaf_url
})
except IndexError : # when list is empty
pass
def build_categories_tree(entry_index, input_list, output_tree, max_weight, set_max_weight=None):
def build_categories_tree(entry_index, input_list, output_tree, output_leaves, max_weight, set_max_weight=None):
for category in input_list:
branch = category.split(' > ')
if not len(branch):
continue
leave = branch[-1]
path = ".:GetRelativeOrigin:."
root = output_tree
for node_name in branch:
......@@ -58,6 +45,9 @@ def build_categories_tree(entry_index, input_list, output_tree, max_weight, set_
if not node_name in [metadata.value for metadata in root]:
root.append(MetadataNode(node_name, entry_index))
if output_leaves != None and node_name == leave:
output_leaves.append(root[-1])
root[-1].path = path
root = root[-1].childs
......
......@@ -181,14 +181,14 @@ class Processor():
output = self.handle_error(
messages.unknown_contextual.format(e),
",;"+pattern+";;"+";;".join(argv)+";,",
error_origin = [':'+str(e)[1:-1]+':','{0['+str(e)[1:-1]+']}']
error_origin = [':'+str(e)[1:-1]+':','{0['+str(e)[1:-1]+']}', ':'+pattern+':'] # first item might be useless ???
)
except AttributeError as e:
output = self.handle_error(
messages.unknown_contextual.format(e),
",;"+pattern+";;"+";;".join(argv)+";,",
error_origin = [str(e).split("'")[-2]]
error_origin = [str(e).split("'")[-2], ':'+pattern+':']
)
except IndexError:
......
......@@ -47,12 +47,13 @@ class Thread:
except TypeError: # if value isn't string but function reference
self.processor.set_function(pattern_name, patterns[pattern_name])
def return_page_around(self, string, destination_page_number, filename):
def return_page_around(self, string, destination_page_number, filename, destination_entry_title):
return string.format(**{
"destination_page":destination_page_number,
"destination_page_url":filename,
"entry_name" : self.current_entry.title,
"entry_id": self.current_entry.id
"entry_id": self.current_entry.id,
"destination_entry_title":destination_entry_title
})
......@@ -78,9 +79,16 @@ class Thread:
def get_next_page(self,argv=list()):
if self.current_page < len(self.pages) - 1:
destination_page_number = str(self.current_page + 1)
next_entry_id = self.current_entry.next_entry.id
filename = self.filename.format(**{"page_number":destination_page_number,"entry_id":next_entry_id})
return self.return_page_around(argv[0], destination_page_number, filename)
try:
next_entry_id = self.current_entry.next_entry.id
destination_entry_title = "" if self.in_thread else self.current_entry.next_entry.title
except AttributeError:
next_entry_id = -1
destination_entry_title = ""
filename = self.filename.format(**{"page_number":destination_page_number,"entry_id":next_entry_id, "destination_entry_title" : destination_entry_title })
return self.return_page_around(argv[0], destination_page_number, filename, destination_entry_title)
else:
return str()
......@@ -91,17 +99,20 @@ class Thread:
destination_page_number = str(self.current_page - 1)
try:
previous_entry_id = self.current_entry.previous_entry.id
destination_entry_title = "" if self.in_thread else self.current_entry.previous_entry.title
except AttributeError:
previous_entry_id = -1
destination_entry_title = ""
# Works, but what a shitty way to code that... May be shortened
if self.current_page == 1:
filename = self.filename.format(**{"page_number" : "", "entry_id" : previous_entry_id})
filename = self.filename.format(**{"page_number" : "", "entry_id" : previous_entry_id, "destination_entry_title": "" if self.in_thread else self.current_entry.title})
else:
filename = self.filename.format(**{"page_number" : destination_page_number, "entry_id" : previous_entry_id})
filename = self.filename.format(**{"page_number" : destination_page_number, "entry_id" : previous_entry_id, "destination_entry_title" : destination_entry_title})
return self.return_page_around(argv[0], destination_page_number, filename)
return self.return_page_around(argv[0], destination_page_number, filename, destination_entry_title)
else:
return str()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment