diff options
Diffstat (limited to 'ogcp')
-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(): |