Refactor config access in server through cdc

This commit is contained in:
Tim Van Baak 2020-02-22 10:55:03 -08:00
parent 0b5488a642
commit 1bd0f1e0c1
1 changed files with 10 additions and 10 deletions

View File

@ -4,8 +4,9 @@ from flask import (
Blueprint, render_template, url_for, redirect, g, flash, request, Markup) Blueprint, render_template, url_for, redirect, g, flash, request, Markup)
from flask_login import login_required, current_user from flask_login import login_required, current_user
from amanuensis.config import json_ro, open_ex, prepend from amanuensis.config import root
from amanuensis.config.loader import ReadOnlyOrderedDict from amanuensis.config.loader import ReadOnlyOrderedDict
from amanuensis.errors import MissingConfigError
from amanuensis.lexicon.manage import valid_add, add_player, add_character from amanuensis.lexicon.manage import valid_add, add_player, add_character
from amanuensis.server.forms import ( from amanuensis.server.forms import (
LexiconConfigForm, LexiconJoinForm,LexiconCharacterForm) LexiconConfigForm, LexiconJoinForm,LexiconCharacterForm)
@ -190,14 +191,13 @@ def get_bp():
articles=articles, articles=articles,
jsonfmt=jsonfmt) jsonfmt=jsonfmt)
filename = f'{cid}.{aid}.json' filename = f'{cid}.{aid}'
path = prepend('lexicon', g.lexicon.id, 'draft', filename) try:
import os with g.lexicon.ctx.draft.read(filename) as a:
if not os.path.isfile(path): article = a
except MissingConfigError:
flash("Draft not found") flash("Draft not found")
return redirect(url_for('lexicon.session', name=name)) return redirect(url_for('lexicon.session', name=name))
with json_ro(path) as a:
article = a
return render_template( return render_template(
'lexicon/editor.html', 'lexicon/editor.html',
@ -225,9 +225,9 @@ def get_bp():
}, },
"contents": "" "contents": ""
} }
filename = f"{cid}.{new_aid}.json" filename = f"{cid}.{new_aid}"
with open_ex('lexicon', g.lexicon.id, 'draft', filename, mode='w') as f: with g.lexicon.ctx.draft.new(filename) as j:
json.dump(article, f) j.update(article)
return redirect(url_for('lexicon.editor', name=name, cid=cid, aid=new_aid)) return redirect(url_for('lexicon.editor', name=name, cid=cid, aid=new_aid))
@bp.route('/session/editor/update', methods=['POST']) @bp.route('/session/editor/update', methods=['POST'])