Add basis for admin lexicon config web editor

This commit is contained in:
Tim Van Baak 2020-01-18 01:18:54 -08:00
parent 69524d03d7
commit 2a314da910
3 changed files with 26 additions and 16 deletions

View File

@ -92,7 +92,7 @@ div.citeblock a.phantom {
span.signature {
text-align: right;
}
textarea#admin_config_text {
textarea#configText {
resize: vertical;
width: 100%;
box-sizing: border-box;

View File

@ -1,15 +1,18 @@
from functools import wraps
import json
from flask import Blueprint, render_template, url_for, redirect
from flask_login import login_required, current_user
from flask_wtf import FlaskForm
from wtforms import TextAreaField, SubmitField
from wtforms import TextAreaField, SubmitField, StringField
import config
import user
import lexicon
class DashboardForm(FlaskForm):
admin_config_text = TextAreaField()
class AdminDashboardForm(FlaskForm):
lexiconName = StringField("Lexicon name")
configText = TextAreaField("Config file")
submit = SubmitField("Submit")
def admin_required(route):
@ -30,19 +33,25 @@ def get_bp():
def home():
return render_template('home/home.html')
@bp.route('/admin/', methods=['GET'])
@bp.route('/admin/', methods=['GET', 'POST'])
@admin_required
def admin():
with config.json_ro('config.json') as j:
global_config = j
import json
text = json.dumps(j, indent=2, allow_nan=False)
form = AdminDashboardForm()
if not form.is_submitted():
return render_template('home/admin.html', form=form)
form = DashboardForm()
if form.is_submitted():
return "k"
if form.lexiconName.data:
lid = None
with config.json_ro('lexicon', 'index.json') as index:
lid = index.get(form.lexiconName.data)
if lid is not None:
with config.json_ro('lexicon', lid, 'config.json') as cfg:
form.configText.data = json.dumps(cfg, indent=2)
form.lexiconName.data = ""
elif form.configText.data:
return "Update config"
else:
form.admin_config_text.data = text
pass
return render_template('home/admin.html', form=form)
return bp

View File

@ -10,7 +10,8 @@
{% block main %}
<form action="" method="post" novalidate>
{{ form.hidden_tag() }}
{{ form.admin_config_text() }}
<p>{{ form.lexiconName.label }}<br>{{ form.lexiconName(size=32) }}</p>
<p>{{ form.configText.label }}<br>{{ form.configText(rows=20) }}</p>
<p>{{ form.submit() }}</p>
</form>
{% endblock %}