Improve admin settings page

The improvements are mostly cosmetic^Wquestionable.
This commit is contained in:
Timotej Lazar 2023-07-07 13:23:51 +02:00
parent dd607dbddd
commit 8c824fe9e6
2 changed files with 16 additions and 7 deletions

View file

@ -14,13 +14,20 @@ def index():
try: try:
if not flask_login.current_user.is_admin: if not flask_login.current_user.is_admin:
return flask.Response('forbidden', status=403, mimetype='text/plain') return flask.Response('forbidden', status=403, mimetype='text/plain')
with db.locked(): with db.locked():
settings = db.read('settings')
if flask.request.method == 'POST': if flask.request.method == 'POST':
form = flask.request.form form = flask.request.form
db.write('settings', dict(zip(form.getlist('setting'), form.getlist('value')))) for name, value in form.items():
if name in settings:
settings[name] = value
db.write('settings', settings)
system.run(system.save_config) system.run(system.save_config)
settings = db.read('settings') return flask.redirect(flask.url_for('config.index'))
return flask.render_template('config/index.html', **locals())
return flask.render_template('config/index.html', settings=settings)
except TimeoutError: except TimeoutError:
return flask.render_template('busy.html') return flask.render_template('busy.html')
except Exception as e: except Exception as e:

View file

@ -5,12 +5,14 @@
Tu lahko urejate splošne nastavitve. Tu lahko urejate splošne nastavitve.
<form id="request" method="POST"> <form id="request" method="POST">
<h2>Nastavitve</h2> <table>
<tbody>
{% for name, value in settings.items() %} {% for name, value in settings.items() %}
<p> <tr>
<input type="hidden" name="setting" value="{{ name }}" /> <td><label for="{{ name }}">{{ name }}</label>
<label>{{ name }}<br><input name="value" value="{{ value }}" /></label> <td><input id="{{ name }}" name="{{ name }}" value="{{ value }}" size="40" />
{% endfor %} {% endfor %}
</table>
<p><button id="submit" type="submit">Shrani</button> <p><button id="submit" type="submit">Shrani</button>
</form> </form>