Make approved articles viewable

This commit is contained in:
Tim Van Baak 2020-04-10 21:28:29 -07:00
parent c9f1f9a44f
commit fd3ef7fbdc
4 changed files with 46 additions and 16 deletions

View File

@ -67,13 +67,19 @@ def get_bp():
@player_required @player_required
def session(name): def session(name):
drafts = [] drafts = []
approved = []
draft_ctx = g.lexicon.ctx.draft draft_ctx = g.lexicon.ctx.draft
draft_filenames = draft_ctx.ls() draft_filenames = draft_ctx.ls()
for draft_filename in draft_filenames: for draft_filename in draft_filenames:
with draft_ctx.read(draft_filename) as draft: with draft_ctx.read(draft_filename) as draft:
if draft.status.ready and not draft.status.approved: if draft.status.ready and not draft.status.approved:
drafts.append(draft) 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): def edit_character(name, form, cid):
if form.validate_on_submit(): if form.validate_on_submit():
@ -152,24 +158,34 @@ def get_bp():
return redirect(url_for('lexicon.session', name=name)) return redirect(url_for('lexicon.session', name=name))
draft_ctx = g.lexicon.ctx.draft 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] 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) parsed_draft = parse_raw_markdown(draft.contents)
rendered_html = parsed_draft.render(PreviewHtmlRenderer( rendered_html = parsed_draft.render(PreviewHtmlRenderer(
{'Article':'default','Phantom':None})) {'Article':'default','Phantom':None}))
form = LexiconReviewForm() # If the article is ready and awaiting review
if not draft.status.approved:
if form.validate_on_submit(): form = LexiconReviewForm()
with draft_ctx.edit(draft_filename) as draft: if form.validate_on_submit():
if not draft.status.ready: if form.approved.data == 'Y':
flash("Article was rescinded") 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)) return redirect(url_for('lexicon.session', name=name))
result = (form.approved.data == "Y")
draft.status.ready = result # If the article was already reviewed and this is just the preview
draft.status.approved = result else:
return redirect(url_for('lexicon.session', name=name)) form = None
return render_template( return render_template(
"lexicon/review.html", "lexicon/review.html",

View File

@ -34,7 +34,7 @@
<a href="{{ url_for('lexicon.session', name=g.lexicon.name) }}"> <a href="{{ url_for('lexicon.session', name=g.lexicon.name) }}">
{{ g.lexicon.title }} {{ g.lexicon.title }}
</a> </a>
{% if article %} {% if article and not article.status.approved %}
<button id="button-submit" onclick="submitArticle()">Submit article</button> <button id="button-submit" onclick="submitArticle()">Submit article</button>
{% endif %} {% endif %}
<span> <span>

View File

@ -17,4 +17,8 @@
</form> </form>
{% endblock %} {% endblock %}
{% if form %}
{% set template_content_blocks = [self.article(), self.evaluation()] %} {% set template_content_blocks = [self.article(), self.evaluation()] %}
{% else %}
{% set template_content_blocks = [self.article()] %}
{% endif %}

View File

@ -21,7 +21,17 @@
{% for article in ready_articles %} {% for article in ready_articles %}
<li> <li>
<a href="{{ url_for('lexicon.review', name=g.lexicon.name, aid=article.aid) }}"> <a href="{{ url_for('lexicon.review', name=g.lexicon.name, aid=article.aid) }}">
Review article by {{ g.lexicon.character[article.character].name }} Review <i>{{ article.title }}</i> by {{ g.lexicon.character[article.character].name }}
</a>
</li>
{% endfor %}
</ul>
<p>Approved articles</p>
<ul>
{% for article in approved_articles %}
<li>
<a href="{{ url_for('lexicon.review', name=g.lexicon.name, aid=article.aid) }}">
<i>{{ article.title }}</i> by {{ g.lexicon.character[article.character].name }}
</a> </a>
</li> </li>
{% endfor %} {% endfor %}