From 7613cd8017e978e771552467a4e10141e120fccb Mon Sep 17 00:00:00 2001 From: Alejandro Sirgo Rica Date: Tue, 3 Sep 2024 12:45:49 +0200 Subject: ogcp: add server ip configuration Enable server view in the main toolbar. Hide Add server and Delete server buttons. Add Update server button. Add server/update view to edit the server addresses. --- ogcp/forms/action_forms.py | 8 +++ ogcp/og_server.py | 6 ++ ogcp/templates/actions/server_update.html | 69 +++++++++++++++++++++++ ogcp/templates/base.html | 3 + ogcp/templates/servers.html | 9 ++- ogcp/views.py | 91 ++++++++++++++++++++++++++++++- 6 files changed, 180 insertions(+), 6 deletions(-) create mode 100644 ogcp/templates/actions/server_update.html diff --git a/ogcp/forms/action_forms.py b/ogcp/forms/action_forms.py index b97ff4d..b4dfe7b 100644 --- a/ogcp/forms/action_forms.py +++ b/ogcp/forms/action_forms.py @@ -276,6 +276,14 @@ class ServerForm(FlaskForm): validators=[InputRequired()]) submit = SubmitField(label=_l('Submit')) +class ServerConfigurationForm(FlaskForm): + server_addr = HiddenField() + addr = FieldList( + StringField(label=_l('Address')), + label=_l('Addresses'), + ) + submit = SubmitField(label=_l('Submit')) + class DeleteRepositoryForm(FlaskForm): repository = SelectField(label=_l('Repository'), validators=[InputRequired()]) diff --git a/ogcp/og_server.py b/ogcp/og_server.py index 1b7fa32..4a1b6ff 100644 --- a/ogcp/og_server.py +++ b/ogcp/og_server.py @@ -37,6 +37,12 @@ class OGServer: json=payload) return r + def delete(self, path, payload): + r = requests.delete(f'{self.URL}{path}', + headers=self.HEADERS, + json=payload) + return r + @property def id(self): ip = self.ip.replace('.', '-') diff --git a/ogcp/templates/actions/server_update.html b/ogcp/templates/actions/server_update.html new file mode 100644 index 0000000..ae2513b --- /dev/null +++ b/ogcp/templates/actions/server_update.html @@ -0,0 +1,69 @@ +{% extends 'servers.html' %} +{% import "bootstrap/wtf.html" as wtf %} + +{% set sidebar_state = 'disabled' %} +{% set btn_back = true %} + +{% block nav_server_add %}active{% endblock %} +{% block content %} + +

{{_('Update server')}}

+ +
+ {{ form.hidden_tag() }} + + {{ form.server_addr() }} + +
+
+ {% for addr in form.addr %} +
+ {{ addr(class="form-control me-2", placeholder=_("Enter IP Address"), required=True) }} + +
+ {% endfor %} +
+ + + {{ form.submit(class="btn btn-success") }} +
+
+ + + +{% endblock %} diff --git a/ogcp/templates/base.html b/ogcp/templates/base.html index cd030e8..5d46135 100644 --- a/ogcp/templates/base.html +++ b/ogcp/templates/base.html @@ -40,6 +40,9 @@ {{ _('Repos') }} {% if current_user.admin %} + diff --git a/ogcp/templates/servers.html b/ogcp/templates/servers.html index bc09c4f..d555f71 100644 --- a/ogcp/templates/servers.html +++ b/ogcp/templates/servers.html @@ -17,7 +17,8 @@ {% endfor %} @@ -26,10 +27,8 @@ {% block commands %} {% if current_user.is_authenticated %} - - + {% if btn_back %}