Update review handler
This commit is contained in:
parent
b8a604e61b
commit
2b56e0c8a6
|
@ -12,7 +12,8 @@ from flask_login import current_user
|
||||||
from amanuensis.lexicon import (
|
from amanuensis.lexicon import (
|
||||||
attempt_publish,
|
attempt_publish,
|
||||||
get_player_characters,
|
get_player_characters,
|
||||||
create_character_in_lexicon)
|
create_character_in_lexicon,
|
||||||
|
get_draft)
|
||||||
from amanuensis.models import LexiconModel
|
from amanuensis.models import LexiconModel
|
||||||
from amanuensis.parser import (
|
from amanuensis.parser import (
|
||||||
parse_raw_markdown,
|
parse_raw_markdown,
|
||||||
|
@ -158,14 +159,14 @@ def settings(name):
|
||||||
@lexicon_param
|
@lexicon_param
|
||||||
@editor_required
|
@editor_required
|
||||||
def review(name):
|
def review(name):
|
||||||
aid = request.args.get('aid')
|
# Ensure the article exists
|
||||||
if not aid:
|
draft = get_draft(g.lexicon, request.args.get('aid'))
|
||||||
|
if not draft:
|
||||||
flash("Unknown article id")
|
flash("Unknown article id")
|
||||||
return redirect(url_for('session.session', name=name))
|
return redirect(url_for('session.session', name=name))
|
||||||
|
|
||||||
draft_ctx = g.lexicon.ctx.draft
|
draft_filename = f'{draft.character}.{draft.aid}'
|
||||||
draft_filename = [fn for fn in draft_ctx.ls() if aid in fn][0]
|
with g.lexicon.ctx.draft.edit(draft_filename) as draft:
|
||||||
with draft_ctx.edit(draft_filename) as draft:
|
|
||||||
# If the article was unreadied in the meantime, abort
|
# If the article was unreadied in the meantime, abort
|
||||||
if not draft.status.ready:
|
if not draft.status.ready:
|
||||||
flash("Article was rescinded")
|
flash("Article was rescinded")
|
||||||
|
@ -176,11 +177,25 @@ def review(name):
|
||||||
rendered_html = preview.contents
|
rendered_html = preview.contents
|
||||||
citations = preview.citations
|
citations = preview.citations
|
||||||
|
|
||||||
# If the article is ready and awaiting review
|
# If the article was already reviewed, just preview it
|
||||||
if not draft.status.approved:
|
if draft.status.approved:
|
||||||
|
return render_template(
|
||||||
|
"session.review.jinja",
|
||||||
|
article_html=Markup(rendered_html),
|
||||||
|
citations=citations)
|
||||||
|
|
||||||
|
# Otherwise, prepare the review form
|
||||||
form = LexiconReviewForm()
|
form = LexiconReviewForm()
|
||||||
if form.validate_on_submit():
|
if not form.validate_on_submit():
|
||||||
if form.approved.data == 'Y':
|
# 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.ready = True
|
||||||
draft.status.approved = True
|
draft.status.approved = True
|
||||||
g.lexicon.log(f"Article '{draft.title}' approved ({draft.aid})")
|
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})")
|
g.lexicon.log(f"Article '{draft.title}' rejected ({draft.aid})")
|
||||||
return redirect(url_for('session.session', name=name))
|
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'])
|
@bp_session.route('/editor/', methods=['GET'])
|
||||||
@lexicon_param
|
@lexicon_param
|
||||||
|
|
Loading…
Reference in New Issue