Move session_edit to settings

This commit is contained in:
Tim Van Baak 2020-01-24 13:14:04 -08:00
parent 9004f60a0c
commit 45b7e43df4
3 changed files with 19 additions and 14 deletions

View File

@ -50,10 +50,10 @@ def get_bp():
def session(name): def session(name):
return render_template('lexicon/session.html') return render_template('lexicon/session.html')
@bp.route('/session/edit/', methods=['GET', 'POST']) @bp.route('/session/settings/', methods=['GET', 'POST'])
@login_required @login_required
@lexicon_param @lexicon_param
def session_edit(name): def settings(name):
# Restrict to editor # Restrict to editor
if not current_user.id == g.lexicon.editor: if not current_user.id == g.lexicon.editor:
flash("Access is forbidden") flash("Access is forbidden")
@ -65,7 +65,7 @@ def get_bp():
if not form.is_submitted(): if not form.is_submitted():
with json_ro(g.lexicon.config_path) as cfg: with json_ro(g.lexicon.config_path) as cfg:
form.configText.data = json.dumps(cfg, indent=2) form.configText.data = json.dumps(cfg, indent=2)
return render_template("lexicon/session_edit.html", form=form) return render_template("lexicon/settings.html", form=form)
if form.validate(): if form.validate():
# Check input is valid json # Check input is valid json
@ -73,7 +73,7 @@ def get_bp():
cfg = json.loads(form.configText.data, object_pairs_hook=ReadOnlyOrderedDict) cfg = json.loads(form.configText.data, object_pairs_hook=ReadOnlyOrderedDict)
except: except:
flash("Invalid JSON") flash("Invalid JSON")
return render_template("lexicon/session_edit.html", form=form) return render_template("lexicon/settings.html", form=form)
# Check input has all the required fields # Check input has all the required fields
# TODO # TODO
# Write the new config # Write the new config
@ -81,9 +81,9 @@ def get_bp():
with open_ex(g.lexicon.config_path, mode='w') as f: with open_ex(g.lexicon.config_path, mode='w') as f:
json.dump(cfg, f, indent='\t') json.dump(cfg, f, indent='\t')
flash("Config updated") flash("Config updated")
return redirect(url_for('lexicon.session_edit', name=name)) return redirect(url_for('lexicon.settings', name=name))
return render_template("lexicon/session_edit.html", form=form) return render_template("lexicon/settings.html", form=form)
@bp.route('/statistics/', methods=['GET']) @bp.route('/statistics/', methods=['GET'])
@login_required @login_required

View File

@ -2,14 +2,19 @@
{% set current_page = "session" %} {% set current_page = "session" %}
{% block title %}Session | {{ lexicon_title }}{% endblock %} {% block title %}Session | {{ lexicon_title }}{% endblock %}
{% block main %} {% set template_content_blocks = [] %}
<h1>Session</h1>
{% endblock %}
{% set template_content_blocks = [self.main()] %}
{% if current_user.id == g.lexicon.editor %} {% if current_user.id == g.lexicon.editor %}
{% block editor_edit %} {% block bl_editor %}
<a href="{{ url_for('lexicon.session_edit', name=g.lexicon.name) }}" style="display:block; text-align:center;">Edit lexicon settings</a> <p>Editor actions</p>
<ul>
<li><a href="{{ url_for('lexicon.settings', name=g.lexicon.name) }}">Edit lexicon settings</a></li>
</ul>
{% endblock %} {% endblock %}
{% set template_content_blocks = [self.editor_edit()] + template_content_blocks %} {% set template_content_blocks = template_content_blocks + [self.bl_editor()] %}
{% endif %} {% endif %}
{% block main %}
<p>Placeholder text for session page</p>
{% endblock %}
{% set template_content_blocks = template_content_blocks + [self.main()] %}