Add basis for admin lexicon config web editor
This commit is contained in:
parent
69524d03d7
commit
2a314da910
|
@ -92,7 +92,7 @@ div.citeblock a.phantom {
|
||||||
span.signature {
|
span.signature {
|
||||||
text-align: right;
|
text-align: right;
|
||||||
}
|
}
|
||||||
textarea#admin_config_text {
|
textarea#configText {
|
||||||
resize: vertical;
|
resize: vertical;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
|
|
@ -1,15 +1,18 @@
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
import json
|
||||||
|
|
||||||
from flask import Blueprint, render_template, url_for, redirect
|
from flask import Blueprint, render_template, url_for, redirect
|
||||||
from flask_login import login_required, current_user
|
from flask_login import login_required, current_user
|
||||||
from flask_wtf import FlaskForm
|
from flask_wtf import FlaskForm
|
||||||
from wtforms import TextAreaField, SubmitField
|
from wtforms import TextAreaField, SubmitField, StringField
|
||||||
|
|
||||||
import config
|
import config
|
||||||
import user
|
import user
|
||||||
|
import lexicon
|
||||||
|
|
||||||
class DashboardForm(FlaskForm):
|
class AdminDashboardForm(FlaskForm):
|
||||||
admin_config_text = TextAreaField()
|
lexiconName = StringField("Lexicon name")
|
||||||
|
configText = TextAreaField("Config file")
|
||||||
submit = SubmitField("Submit")
|
submit = SubmitField("Submit")
|
||||||
|
|
||||||
def admin_required(route):
|
def admin_required(route):
|
||||||
|
@ -30,19 +33,25 @@ def get_bp():
|
||||||
def home():
|
def home():
|
||||||
return render_template('home/home.html')
|
return render_template('home/home.html')
|
||||||
|
|
||||||
@bp.route('/admin/', methods=['GET'])
|
@bp.route('/admin/', methods=['GET', 'POST'])
|
||||||
@admin_required
|
@admin_required
|
||||||
def admin():
|
def admin():
|
||||||
with config.json_ro('config.json') as j:
|
form = AdminDashboardForm()
|
||||||
global_config = j
|
if not form.is_submitted():
|
||||||
import json
|
|
||||||
text = json.dumps(j, indent=2, allow_nan=False)
|
|
||||||
|
|
||||||
form = DashboardForm()
|
|
||||||
if form.is_submitted():
|
|
||||||
return "k"
|
|
||||||
else:
|
|
||||||
form.admin_config_text.data = text
|
|
||||||
return render_template('home/admin.html', form=form)
|
return render_template('home/admin.html', form=form)
|
||||||
|
|
||||||
|
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:
|
||||||
|
pass
|
||||||
|
return render_template('home/admin.html', form=form)
|
||||||
|
|
||||||
return bp
|
return bp
|
||||||
|
|
|
@ -10,7 +10,8 @@
|
||||||
{% block main %}
|
{% block main %}
|
||||||
<form action="" method="post" novalidate>
|
<form action="" method="post" novalidate>
|
||||||
{{ form.hidden_tag() }}
|
{{ 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>
|
<p>{{ form.submit() }}</p>
|
||||||
</form>
|
</form>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
Loading…
Reference in New Issue