diff options
author | Javier Hernandez <jhernandez@soleta.eu> | 2024-01-10 11:23:36 +0100 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-01-10 11:31:08 +0100 |
commit | 695fcfe6255fd53b19b416e8375b48d2dc5595e4 (patch) | |
tree | 72927876587a1ca19b2e8cc6172346fa133ceb96 /ogcp/views.py | |
parent | 58b5b2eca00acc14510dbf2c741f12d7e799a264 (diff) |
src: Add support for adding folders
Add support to create a folder able to contain multiple computers.
Add support for adding a folder able to contain rooms
Diffstat (limited to 'ogcp/views.py')
-rw-r--r-- | ogcp/views.py | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/ogcp/views.py b/ogcp/views.py index b124287..bd179cd 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, RepoForm + ServerForm, DeleteRepositoryForm, RepoForm, FolderForm ) from flask_login import ( current_user, LoginManager, @@ -990,6 +990,45 @@ def action_client_update(): return render_template('actions/client_details.html', form=form, parent="scopes.html", scopes=scopes) +@app.route('/action/folder/add', methods=['GET']) +@login_required +def action_folder_add(): + form = FolderForm() + params = request.args.to_dict() + room = params.get('scope-room') + center = params.get('scope-center') + if room and center: + flash(_('Please, select either a room or a center'), category='error') + return redirect(url_for('scopes')) + if not room and not center: + flash(_('Please, select a room or a center'), category='error') + return redirect(url_for('scopes')) + form.server.data = params['scope-server'] + form.room.data = room + form.center.data = center + form.submit.render_kw = {"formaction": url_for('action_folder_add_post')} + scopes, _ = get_scopes() + return render_template('actions/folder_add.html', form=form, + parent="scopes.html", scopes=scopes) + +@app.route('/action/folder/add', methods=['POST']) +def action_folder_add_post(): + form = FolderForm(request.form) + payload = {"name": form.name.data} + if form.center.data: + payload["center"] = int(form.center.data) + if form.room.data: + payload["room"] = int(form.room.data) + + server = get_server_from_ip_port(form.server.data) + r = server.post('/folder/add', payload) + if r.status_code != requests.codes.ok: + flash(_('ogServer: error adding folder'), + category='error') + else: + flash(_('Folder added successfully'), category='info') + return redirect(url_for("scopes")) + @app.route('/action/client/add', methods=['GET', 'POST']) @login_required def action_client_add(): |