diff options
Diffstat (limited to 'src/hydrilla/proxy/web_ui/root.py')
-rw-r--r-- | src/hydrilla/proxy/web_ui/root.py | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/hydrilla/proxy/web_ui/root.py b/src/hydrilla/proxy/web_ui/root.py index 21c491b..a28fde8 100644 --- a/src/hydrilla/proxy/web_ui/root.py +++ b/src/hydrilla/proxy/web_ui/root.py @@ -45,7 +45,6 @@ from ...translations import translation as make_translation from ... import item_infos from .. import state as st from .. import http_messages -from . import options from . import rules from . import repos from . import items @@ -100,7 +99,7 @@ class WebUIAppImpl(_app.WebUIApp): self.before_request(authenticate_by_referrer) - for blueprint in [rules.bp, repos.bp, items.bp, prompts.bp, options.bp]: + for blueprint in [rules.bp, repos.bp, items.bp, prompts.bp]: self.register_blueprint(blueprint) # Flask app is not thread-safe and has to be accompanied by an ugly lock. This @@ -110,10 +109,35 @@ app = WebUIAppImpl() app_lock = Lock() -@app.route('/') -def home() -> str: - return flask.render_template('index.html.jinja') - +@app.route('/', methods=['GET']) +def home(errors: t.Mapping[str, bool] = {}) -> werkzeug.Response: + html = flask.render_template('index.html.jinja', **errors) + return flask.make_response(html, 200) + +@app.route('/', methods=['POST']) +def home_post() -> werkzeug.Response: + action = flask.request.form['action'] + + state = _app.get_haketilo_state() + + if action == 'use_enabled': + state.update_settings(mapping_use_mode=st.MappingUseMode.WHEN_ENABLED) + elif action == 'use_auto': + state.update_settings(mapping_use_mode=st.MappingUseMode.AUTO) + elif action == 'use_question': + state.update_settings(mapping_use_mode=st.MappingUseMode.QUESTION) + elif action == 'allow_scripts': + state.update_settings(default_allow_scripts=True) + elif action == 'block_scripts': + state.update_settings(default_allow_scripts=False) + elif action == 'user_make_advanced': + state.update_settings(advanced_user=True) + elif action == 'user_make_simple': + state.update_settings(advanced_user=False) + else: + raise ValueError() + + return flask.redirect(flask.url_for('.home'), 303) def process_request( request_info: http_messages.RequestInfo, |