Update review handler

This commit is contained in:
Tim Van Baak 2020-04-28 09:06:03 -07:00
parent b8a604e61b
commit 2b56e0c8a6
1 changed files with 34 additions and 29 deletions

View File

@ -12,7 +12,8 @@ from flask_login import current_user
from amanuensis.lexicon import (
attempt_publish,
get_player_characters,
create_character_in_lexicon)
create_character_in_lexicon,
get_draft)
from amanuensis.models import LexiconModel
from amanuensis.parser import (
parse_raw_markdown,
@ -158,14 +159,14 @@ def settings(name):
@lexicon_param
@editor_required
def review(name):
aid = request.args.get('aid')
if not aid:
# Ensure the article exists
draft = get_draft(g.lexicon, request.args.get('aid'))
if not draft:
flash("Unknown article id")
return redirect(url_for('session.session', name=name))
draft_ctx = g.lexicon.ctx.draft
draft_filename = [fn for fn in draft_ctx.ls() if aid in fn][0]
with draft_ctx.edit(draft_filename) as draft:
draft_filename = f'{draft.character}.{draft.aid}'
with g.lexicon.ctx.draft.edit(draft_filename) as draft:
# If the article was unreadied in the meantime, abort
if not draft.status.ready:
flash("Article was rescinded")
@ -176,11 +177,25 @@ def review(name):
rendered_html = preview.contents
citations = preview.citations
# If the article is ready and awaiting review
if not draft.status.approved:
# If the article was already reviewed, just preview it
if draft.status.approved:
return render_template(
"session.review.jinja",
article_html=Markup(rendered_html),
citations=citations)
# Otherwise, prepare the review form
form = LexiconReviewForm()
if form.validate_on_submit():
if form.approved.data == 'Y':
if not form.validate_on_submit():
# GET or POST with invalid data
return render_template(
"session.review.jinja",
form=form,
article_html=Markup(rendered_html),
citations=citations)
# POST with valid data
if form.approved.data == LexiconReviewForm.APPROVED:
draft.status.ready = True
draft.status.approved = True
g.lexicon.log(f"Article '{draft.title}' approved ({draft.aid})")
@ -192,16 +207,6 @@ def review(name):
g.lexicon.log(f"Article '{draft.title}' rejected ({draft.aid})")
return redirect(url_for('session.session', name=name))
# If the article was already reviewed and this is just the preview
else:
form = None
return render_template(
"session.review.jinja",
form=form,
article_html=Markup(rendered_html),
citations=citations)
@bp_session.route('/editor/', methods=['GET'])
@lexicon_param