Refactor info lookup into preview renderer ctor

This commit is contained in:
Tim Van Baak 2020-04-19 19:57:08 -07:00
parent 317fc07a45
commit 2705764a6a
2 changed files with 8 additions and 18 deletions

View File

@ -56,12 +56,12 @@ class HtmlRenderer():
class PreviewHtmlRenderer():
def __init__(self, article_map):
"""
article_map maps article titles to character ids. An article
present in the map but mapped to None is a phantom article.
"""
self.article_map = article_map
def __init__(self, lexicon):
with lexicon.ctx.read('info') as info:
self.article_map = {
title: article.character
for title, article in info.items()
}
def TextSpan(self, span):
return span.innertext

View File

@ -185,12 +185,7 @@ def get_bp():
return redirect(url_for('lexicon.session', name=name))
parsed_draft = parse_raw_markdown(draft.contents)
with g.lexicon.ctx.read('info') as info:
authorship = {
title: article.character
for title, article in info.items()
}
rendered_html = parsed_draft.render(PreviewHtmlRenderer(authorship))
rendered_html = parsed_draft.render(PreviewHtmlRenderer(g.lexicon))
# If the article is ready and awaiting review
if not draft.status.approved:
@ -324,12 +319,7 @@ def get_bp():
# check if article was previously approved
# check extrinsic constraints for blocking errors
parsed_draft = parse_raw_markdown(article['contents'])
with g.lexicon.ctx.read('info') as info:
authorship = {
title: article.character
for title, article in info.items()
}
rendered_html = parsed_draft.render(PreviewHtmlRenderer(authorship))
rendered_html = parsed_draft.render(PreviewHtmlRenderer(g.lexicon))
features = parsed_draft.render(FeatureCounter())
filename = f'{article["character"]}.{article["aid"]}'