diff options
author | Javier Hernandez <jhernandez@soleta.eu> | 2023-12-05 11:02:28 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2023-12-05 11:38:26 +0100 |
commit | 15dd4c2a8f690dcda27c453b3f8659cd39da525d (patch) | |
tree | aae77ca0c9b0c6d643c60bf2beec130e123bc623 | |
parent | 152337b6bdb8ad95c516ec818d9f625cb9dff54d (diff) |
views: add action to update repo
allow the user to update a repo by selecting one and pressing the update
button.
-rw-r--r-- | ogcp/templates/repos.html | 2 | ||||
-rw-r--r-- | ogcp/views.py | 37 |
2 files changed, 39 insertions, 0 deletions
diff --git a/ogcp/templates/repos.html b/ogcp/templates/repos.html index 8477d29..31a4226 100644 --- a/ogcp/templates/repos.html +++ b/ogcp/templates/repos.html @@ -54,6 +54,8 @@ form="reposForm" formaction="{{ url_for('repo_add_get') }}" formmethod="get"> <input class="btn btn-light {% block nav_repo_delete %}{% endblock %}" type="submit" value="{{ _('Delete repo') }}" form="reposForm" formaction="{{ url_for('action_repo_delete') }}" formmethod="get"> + <input class="btn btn-light {% block nav_repo_update %}{% endblock %}" type="submit" value="{{ _('Update repo') }}" + form="reposForm" formaction="{{ url_for('action_repo_update') }}" formmethod="get"> {% if btn_back %} <button class="btn btn-danger ml-3" type="button" id="backButton" onclick="history.back()"> diff --git a/ogcp/views.py b/ogcp/views.py index 53bad26..337d29c 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1515,6 +1515,43 @@ def repo_add_post(): flash(_('Repo added successfully'), category='info') return redirect(url_for("manage_repos")) +@app.route('/action/repo/update', methods=['GET', 'POST']) +@login_required +def action_repo_update(): + form = RepoForm(request.form) + if request.method == 'POST': + server = get_server_from_ip_port(form.server.data) + payload = { 'repo_id': int(form.repo_id.data), + 'name': form.name.data, + 'ip': form.ip.data, + 'center': 1} + r = server.post('/repository/update', payload) + if r.status_code != requests.codes.ok: + flash(_('ogServer: error updating repo'), + category='error') + else: + flash(_('Repo updated successfully'), + category='info') + return redirect(url_for('manage_repos')) + else: + params = request.args.to_dict() + repos = parse_elements(params) + if not validate_elements(repos, max_len=1): + return redirect(url_for('manage_repos')) + repo_id = repos.pop() + server_ip_port = params.get('repos-server') + server = get_server_from_ip_port(server_ip_port) + repository = get_repository(int(repo_id), server) + + form.server.data = server_ip_port + form.repo_id.data = repo_id + form.name.data = repository['name'] + form.ip.data = repository['ip'] + + responses = multi_request('get', '/repositories') + return render_template('actions/repos_update.html', form=form, + repos_resp=responses) + @app.route('/action/repo/delete', methods=['GET', 'POST']) @login_required def action_repo_delete(): |