summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJavier Hernandez <jhernandez@soleta.eu>2023-12-01 15:55:15 +0100
committerOpenGnSys Support Team <soporte-og@soleta.eu>2023-12-01 17:20:08 +0100
commit285843634162860b1ba19f71834f06f4fca54583 (patch)
treeacff35ea64421e7153fa9ea6d39172cd3b6ef07f /ogcp/views.py
parent215e3c2fc0453122b5fefcc7fe39f14797bee17f (diff)
src: add menu to manage repos
The menu includes a list of the repos of each server. The user can select a server or a repo to make changes. As of now, the only action possible is to add a repo to selected server. The work contained in this commit can be structured in: 1. Add the repos menu: - Add a 'repos' button in the menus bar (base.html). - Add repos.html template to create the management repos menu. - In ogcp.js, add function to store in browser's local storage which elements of the sidebar are uncollapsed. This saves the sidebar state after a page refresh. - Add manage_repos() in views.py 2. Allow to add a repo: - Add template with form to add a repo (repos_details.html) - Create RepoForm(FlaskForm) in action_forms.py - Add repo_add_get() and repo_add_post() in views.py
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py43
1 files changed, 42 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index eb6bfec..fb7d6bb 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -13,7 +13,7 @@ from ogcp.forms.action_forms import (
SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm,
RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm, OgliveForm,
GenericForm, SelectClientForm, ImageUpdateForm, ImportClientsForm,
- ServerForm, DeleteRepositoryForm
+ ServerForm, DeleteRepositoryForm, RepoForm
)
from flask_login import (
current_user, LoginManager,
@@ -1475,6 +1475,47 @@ def images():
return render_template('images.html', responses=responses)
+@app.route('/repos/', methods=['GET'])
+@login_required
+def manage_repos():
+ responses = multi_request('get', '/repositories')
+ return render_template('repos.html', repos_resp=responses)
+
+@app.route('/repo/add', methods=['GET'])
+@login_required
+def repo_add_get():
+ form = RepoForm()
+ params = request.args.to_dict()
+ if not params.get('selected-server'):
+ flash(_('Please, select a server'), category='error')
+ return redirect(url_for('manage_repos'))
+
+ form.server.data = params['selected-server']
+ form.create.render_kw = {"formaction": url_for('repo_add_post')}
+
+ 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():
+ 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')
+ else:
+ flash(_('Repo added successfully'), category='info')
+ return redirect(url_for("manage_repos"))
+
@app.route('/servers/', methods=['GET'])
@login_required
def manage_servers():