From fd3ef7fbdceda9c41220a50711386340e8da1592 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Fri, 10 Apr 2020 21:28:29 -0700 Subject: [PATCH] Make approved articles viewable --- amanuensis/server/lexicon.py | 42 ++++++++++++++++------- amanuensis/templates/lexicon/editor.html | 2 +- amanuensis/templates/lexicon/review.html | 6 +++- amanuensis/templates/lexicon/session.html | 12 ++++++- 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/amanuensis/server/lexicon.py b/amanuensis/server/lexicon.py index fac9885..9a0c286 100644 --- a/amanuensis/server/lexicon.py +++ b/amanuensis/server/lexicon.py @@ -67,13 +67,19 @@ def get_bp(): @player_required def session(name): drafts = [] + approved = [] draft_ctx = g.lexicon.ctx.draft draft_filenames = draft_ctx.ls() for draft_filename in draft_filenames: with draft_ctx.read(draft_filename) as draft: if draft.status.ready and not draft.status.approved: drafts.append(draft) - return render_template('lexicon/session.html', ready_articles=drafts) + if draft.status.approved: + approved.append(draft) + return render_template( + 'lexicon/session.html', + ready_articles=drafts, + approved_articles=approved) def edit_character(name, form, cid): if form.validate_on_submit(): @@ -152,24 +158,34 @@ def get_bp(): return redirect(url_for('lexicon.session', name=name)) draft_ctx = g.lexicon.ctx.draft - # TODO do this not terribly draft_filename = [fn for fn in draft_ctx.ls() if aid in fn][0] - with draft_ctx.read(draft_filename) as draft: + with draft_ctx.edit(draft_filename) as draft: + # If the article was unreadied in the meantime, abort + if not draft.status.ready: + flash("Article was rescinded") + return redirect(url_for('lexicon.session', name=name)) + parsed_draft = parse_raw_markdown(draft.contents) rendered_html = parsed_draft.render(PreviewHtmlRenderer( {'Article':'default','Phantom':None})) - form = LexiconReviewForm() - - if form.validate_on_submit(): - with draft_ctx.edit(draft_filename) as draft: - if not draft.status.ready: - flash("Article was rescinded") + # If the article is ready and awaiting review + if not draft.status.approved: + form = LexiconReviewForm() + if form.validate_on_submit(): + if form.approved.data == 'Y': + draft.status.ready = True + draft.status.approved = True + g.lexicon.add_log(f"Article '{draft.title}' approved ({draft.aid})") + else: + draft.status.ready = False + draft.status.approved = False + g.lexicon.add_log(f"Article '{draft.title}' rejected ({draft.aid})") return redirect(url_for('lexicon.session', name=name)) - result = (form.approved.data == "Y") - draft.status.ready = result - draft.status.approved = result - return redirect(url_for('lexicon.session', name=name)) + + # If the article was already reviewed and this is just the preview + else: + form = None return render_template( "lexicon/review.html", diff --git a/amanuensis/templates/lexicon/editor.html b/amanuensis/templates/lexicon/editor.html index 8e6983c..5eaf9d9 100644 --- a/amanuensis/templates/lexicon/editor.html +++ b/amanuensis/templates/lexicon/editor.html @@ -34,7 +34,7 @@ {{ g.lexicon.title }} - {% if article %} + {% if article and not article.status.approved %} {% endif %} diff --git a/amanuensis/templates/lexicon/review.html b/amanuensis/templates/lexicon/review.html index 395b1c3..78b89f1 100644 --- a/amanuensis/templates/lexicon/review.html +++ b/amanuensis/templates/lexicon/review.html @@ -17,4 +17,8 @@ {% endblock %} -{% set template_content_blocks = [self.article(), self.evaluation()] %} \ No newline at end of file +{% if form %} +{% set template_content_blocks = [self.article(), self.evaluation()] %} +{% else %} +{% set template_content_blocks = [self.article()] %} +{% endif %} \ No newline at end of file diff --git a/amanuensis/templates/lexicon/session.html b/amanuensis/templates/lexicon/session.html index 9b2aa4c..550fa6b 100644 --- a/amanuensis/templates/lexicon/session.html +++ b/amanuensis/templates/lexicon/session.html @@ -21,7 +21,17 @@ {% for article in ready_articles %}
  • - Review article by {{ g.lexicon.character[article.character].name }} + Review {{ article.title }} by {{ g.lexicon.character[article.character].name }} + +
  • + {% endfor %} + +

    Approved articles

    +