summaryrefslogtreecommitdiffstats
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
parent9a6981d289865b3a22c645718e0e90865ea14638 (diff)
Create "Add Repository" form and view
Creates "Add repository" form with the required inputs: name and IP.
-rw-r--r--ogcp/forms/action_forms.py7
-rw-r--r--ogcp/templates/actions/add_repository.html17
-rw-r--r--ogcp/templates/repositories.html2
-rw-r--r--ogcp/views.py31
4 files changed, 56 insertions, 1 deletions
diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py
index 1ee7b72..b1da58b 100644
--- a/ogcp/forms/action_forms.py
+++ b/ogcp/forms/action_forms.py
@@ -185,3 +185,10 @@ class ImageDetailsForm(FlaskForm):
modified = StringField(label=_l('Modified'))
permissions = StringField(label=_l('Permissions'))
software_id = StringField(label=_l('Software id'))
+
+class RepositoryForm(FlaskForm):
+ name = StringField(label=_l('Name'),
+ validators=[InputRequired()])
+ ip = StringField(label=_l('IP'),
+ validators=[InputRequired()])
+ submit = SubmitField(label=_l('Submit'))
diff --git a/ogcp/templates/actions/add_repository.html b/ogcp/templates/actions/add_repository.html
new file mode 100644
index 0000000..e7c50fa
--- /dev/null
+++ b/ogcp/templates/actions/add_repository.html
@@ -0,0 +1,17 @@
+{% extends 'repositories.html' %}
+{% import "bootstrap/wtf.html" as wtf %}
+
+{% set sidebar_state = 'disabled' %}
+{% set btn_back = true %}
+
+{% block nav_repository_add %}active{% endblock %}
+{% block content %}
+
+<h1 class="m-5">{{_('Add a repository')}}</h1>
+
+{{ wtf.quick_form(form,
+ action=url_for('repository_add_post'),
+ method='post',
+ button_map={'submit_btn':'primary'}) }}
+
+{% endblock %}
diff --git a/ogcp/templates/repositories.html b/ogcp/templates/repositories.html
index 3bed073..2333a88 100644
--- a/ogcp/templates/repositories.html
+++ b/ogcp/templates/repositories.html
@@ -24,6 +24,8 @@
{% endblock %}
{% block commands %}
+ <input class="btn btn-light {% block nav_repository_add %}{% endblock %}" type="submit" value="{{ _('Add repository') }}"
+ form="repositoriesForm" formaction="{{ url_for('repository_add_get') }}" formmethod="get">
{% if btn_back %}
<button class="btn btn-danger ml-3" type="button" id="backButton" onclick="history.back()">
{{ _("Back") }}
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():