summaryrefslogtreecommitdiffstats
path: root/ogcp/views.py
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2022-07-01 10:36:20 +0200
committerJavier Sánchez Parra <jsanchez@soleta.eu>2022-07-04 15:34:02 +0200
commitc068bd21448c2e202720a9daf2923a375c96370d (patch)
treec893d4908ad306218f0c8e5af2e68eb99cdac55b /ogcp/views.py
parent9a6981d289865b3a22c645718e0e90865ea14638 (diff)
Create "Add Repository" form and view
Creates "Add repository" form with the required inputs: name and IP.
Diffstat (limited to 'ogcp/views.py')
-rw-r--r--ogcp/views.py31
1 files changed, 30 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py
index 16ba0b6..c391302 100644
--- a/ogcp/views.py
+++ b/ogcp/views.py
@@ -12,7 +12,8 @@ from ogcp.forms.action_forms import (
WOLForm, SetupForm, ClientDetailsForm, ImageDetailsForm, HardwareForm,
SessionForm, ImageRestoreForm, ImageCreateForm, SoftwareForm, BootModeForm,
RoomForm, DeleteRoomForm, CenterForm, DeleteCenterForm, OgliveForm,
- GenericForm, SelectClientForm, ImageUpdateForm, ImportClientsForm
+ GenericForm, SelectClientForm, ImageUpdateForm, ImportClientsForm,
+ RepositoryForm
)
from flask_login import (
current_user, LoginManager,
@@ -1245,6 +1246,34 @@ def repositories():
return render_template('repositories.html', repositories=repositories)
+@app.route('/repositories/add', methods=['GET'])
+@login_required
+def repository_add_get():
+ form = RepositoryForm()
+ r = g.server.get('/repositories')
+ repositories = r.json()['repositories']
+ return render_template('actions/add_repository.html', form=form,
+ repositories=repositories)
+
+
+@app.route('/repositories/add', methods=['POST'])
+@login_required
+def repository_add_post():
+ form = RepositoryForm(request.form)
+ if not form.validate():
+ flash(form.errors, category='error')
+ return redirect(url_for('repositories'))
+
+ payload = {"name": form.name.data,
+ "ip": form.ip.data}
+ r = g.server.post('/repository/add', payload)
+ if r.status_code != requests.codes.ok:
+ flash(_('ogServer: error adding the repository'), category='error')
+ else:
+ flash(_('Repository added successfully'), category='info')
+ return redirect(url_for("repositories"))
+
+
@app.route('/users/', methods=['GET'])
@login_required
def users():