Refactor info lookup into preview renderer ctor
This commit is contained in:
parent
317fc07a45
commit
2705764a6a
|
@ -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
|
||||
|
|
|
@ -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"]}'
|
||||
|
|
Loading…
Reference in New Issue