From 83b033a779fcf6afb4c43590d81a2c7e3a6a195e Mon Sep 17 00:00:00 2001 From: augustin64 Date: Thu, 26 Oct 2023 14:33:06 +0200 Subject: [PATCH] Testing a simple API --- partitioncloud/modules/albums.py | 18 +++++++++++++++--- partitioncloud/modules/groupe.py | 8 +++++++- partitioncloud/modules/partition.py | 10 ++++++++-- 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/partitioncloud/modules/albums.py b/partitioncloud/modules/albums.py index c664ce1..509e93b 100644 --- a/partitioncloud/modules/albums.py +++ b/partitioncloud/modules/albums.py @@ -131,7 +131,13 @@ def create_album(): except db.IntegrityError: pass - return redirect(f"/albums/{uuid}") + if "response" in request.args and request.args["response"] == "json": + return { + "status": "ok", + "uuid": uuid + } + else: + return redirect(f"/albums/{uuid}") flash(error) return redirect(request.referrer) @@ -291,8 +297,14 @@ def add_partition(album_uuid): except db.IntegrityError: pass - flash(f"Partition {request.form['name']} ajoutée") - return redirect(f"/albums/{album.uuid}") + if "response" in request.args and request.args["response"] == "json": + return { + "status": "ok", + "uuid": partition_uuid + } + else: + flash(f"Partition {request.form['name']} ajoutée") + return redirect(f"/albums/{album.uuid}") @bp.route("/add-partition", methods=["POST"]) diff --git a/partitioncloud/modules/groupe.py b/partitioncloud/modules/groupe.py index bd62d3a..9057ef0 100644 --- a/partitioncloud/modules/groupe.py +++ b/partitioncloud/modules/groupe.py @@ -89,7 +89,13 @@ def create_groupe(): except db.IntegrityError: pass - return redirect(f"/groupe/{uuid}") + if "response" in request.args and request.args["response"] == "json": + return { + "status": "ok", + "uuid": uuid + } + else: + return redirect(f"/groupe/{uuid}") flash(error) return redirect(request.referrer) diff --git a/partitioncloud/modules/partition.py b/partitioncloud/modules/partition.py index d5d70f4..9e57261 100644 --- a/partitioncloud/modules/partition.py +++ b/partitioncloud/modules/partition.py @@ -99,8 +99,14 @@ def add_attachment(uuid): except db.IntegrityError: pass - - return redirect(f"/partition/{partition.uuid}/attachments") + + if "response" in request.args and request.args["response"] == "json": + return { + "status": "ok", + "uuid": attachment_uuid + } + else: + return redirect(f"/partition/{partition.uuid}/attachments") @bp.route("/attachment/.")