diff options
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(): |