views: change repo add view to follow convention

combine repo_add_get and repo_add_post into one, action_repo_add. This
is to follow convention across all the views and to clarify that it is
an action.

rename repos_details template to repos_add. Now it is clear the purpose
of each action template; there is one for each: add, delete and update
master v1.1.3-6
Javier Hernandez 2023-12-05 11:48:09 +01:00 committed by OpenGnSys Support Team
parent 15dd4c2a8f
commit f76c0ed24d
3 changed files with 30 additions and 33 deletions

View File

@ -7,10 +7,10 @@
{% block nav_repos_add %}active{% endblock %}
{% block content %}
<h1 class="m-5">{{_('Repo details')}}</h1>
<h1 class="m-5">{{_('Add repo')}}</h1>
{{ wtf.quick_form(form,
action=url_for('repo_add_post'),
action=url_for('action_repo_add'),
method='post',
button_map={'submit': 'primary'},
extra_classes="mx-5") }}

View File

@ -51,7 +51,7 @@
{% block commands %}
<input class="btn btn-light {% block nav_repo_add %}{% endblock %}" type="submit" value="{{ _('Add repo') }}"
form="reposForm" formaction="{{ url_for('repo_add_get') }}" formmethod="get">
form="reposForm" formaction="{{ url_for('action_repo_add') }}" 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') }}"

View File

@ -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