diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-08-24 10:47:33 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-09-28 12:54:53 +0200 |
commit | d516b9decad07b940b3cd117fc4e353dd8bbe7d2 (patch) | |
tree | 2ab6f78e067d88a9dce1043e496b1d5af283464b /src/hydrilla/proxy/web_ui/packages.py | |
parent | 964bd44649aaf03c9afea06eadad0443032d8b77 (diff) | |
download | haketilo-hydrilla-d516b9decad07b940b3cd117fc4e353dd8bbe7d2.tar.gz haketilo-hydrilla-d516b9decad07b940b3cd117fc4e353dd8bbe7d2.zip |
make repo packages (mappings) load as uninstalled; make them installable through the web UI
Diffstat (limited to 'src/hydrilla/proxy/web_ui/packages.py')
-rw-r--r-- | src/hydrilla/proxy/web_ui/packages.py | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/src/hydrilla/proxy/web_ui/packages.py b/src/hydrilla/proxy/web_ui/packages.py index 85e5d00..ac8b480 100644 --- a/src/hydrilla/proxy/web_ui/packages.py +++ b/src/hydrilla/proxy/web_ui/packages.py @@ -132,15 +132,50 @@ def show_package(mapping_id: str) -> werkzeug.Response: flask.abort(404) @bp.route('/packages/viewversion/<string:mapping_version_id>') -def show_package_version(mapping_version_id: str) -> werkzeug.Response: +def show_package_version( + mapping_version_id: str, + errors: t.Mapping[str, bool] = {} +) -> werkzeug.Response: try: store = _app.get_haketilo_state().mapping_version_store() display_info = store.get(mapping_version_id).get_display_info() html = flask.render_template( 'packages/show_single_version.html.jinja', - display_info = display_info + display_info = display_info, + **errors ) return flask.make_response(html, 200) except st.MissingItemError: flask.abort(404) + +@bp.route('/packages/viewversion/<string:mapping_version_id>', methods=['POST']) +def alter_package_version(mapping_version_id: str) -> werkzeug.Response: + form_data = flask.request.form + action = form_data['action'] + + try: + store = _app.get_haketilo_state().mapping_version_store() + mapping_version_ref = store.get(mapping_version_id) + + if action == 'install_package': + mapping_version_ref.install() + elif action == 'uninstall_package': + mapping_version_ref.uninstall() + return flask.redirect(flask.url_for('.packages')) + else: + raise ValueError() + except st.ImpossibleSituation: + return show_package_version( + mapping_version_id, + {'uninstall_disallowed': True} + ) + except st.MissingItemError: + flask.abort(404) + + return flask.redirect( + flask.url_for( + '.show_package_version', + mapping_version_id = mapping_version_id + ) + ) |