diff options
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 57 |
1 files changed, 27 insertions, 30 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index 337d29c..7c50ac9 100644 --- a/ogcp/views.py +++ b/ogcp/views.py @@ -1481,39 +1481,36 @@ def manage_repos(): responses = multi_request('get', '/repositories') return render_template('repos.html', repos_resp=responses) -@app.route('/repo/add', methods=['GET']) +@app.route('/action/repo/add', methods=['POST', 'GET']) @login_required -def repo_add_get(): - form = RepoForm() - params = request.args.to_dict() - if not params.get('repos-server'): - flash(_('Please, select a server'), category='error') - return redirect(url_for('manage_repos')) - - form.server.data = params['repos-server'] - - responses = multi_request('get', '/repositories') - return render_template('actions/repos_details.html', form=form, - repos_resp=responses) - -@app.route('/repo/add', methods=['POST']) -@login_required -def repo_add_post(): +def action_repo_add(): form = RepoForm(request.form) - if not form.validate(): - flash(form.errors, category='error') - return redirect(url_for('manage_repos')) - payload = {"name": form.name.data, - "ip": form.ip.data, - "center": 1} - server = get_server_from_ip_port(form.server.data) - r = server.post('/repository/add', payload) - if r.status_code != requests.codes.ok: - flash(_('ogServer: error adding repo'), - category='error') + if request.method == 'POST': + if not form.validate(): + flash(form.errors, category='error') + return redirect(url_for('manage_repos')) + payload = {"name": form.name.data, + "ip": form.ip.data, + "center": 1} + server = get_server_from_ip_port(form.server.data) + r = server.post('/repository/add', payload) + if r.status_code != requests.codes.ok: + flash(_('ogServer: error adding repo'), + category='error') + else: + flash(_('Repo added successfully'), category='info') + return redirect(url_for("manage_repos")) else: - flash(_('Repo added successfully'), category='info') - return redirect(url_for("manage_repos")) + params = request.args.to_dict() + if not params.get('repos-server'): + flash(_('Please, select a server'), category='error') + return redirect(url_for('manage_repos')) + + form.server.data = params['repos-server'] + + responses = multi_request('get', '/repositories') + return render_template('actions/repos_add.html', form=form, + repos_resp=responses) @app.route('/action/repo/update', methods=['GET', 'POST']) @login_required |