From 18bc26cc402b9f646b9fca88f74fbef0befc8904 Mon Sep 17 00:00:00 2001 From: Christian Glatthard Date: Mon, 10 Aug 2015 10:28:35 +0200 Subject: [PATCH 1/2] remove workaround get requests before post requests --- ipynbsrv/web/views/collaborationgroups.py | 2 -- ipynbsrv/web/views/containers.py | 4 ---- ipynbsrv/web/views/shares.py | 3 --- 3 files changed, 9 deletions(-) diff --git a/ipynbsrv/web/views/collaborationgroups.py b/ipynbsrv/web/views/collaborationgroups.py index cfc75e3..0d3843f 100644 --- a/ipynbsrv/web/views/collaborationgroups.py +++ b/ipynbsrv/web/views/collaborationgroups.py @@ -71,8 +71,6 @@ def create(request): client = get_httpclient_instance(request) try: - # stupid create workaround (see containers) - client.collaborationgroups.get() client.collaborationgroups.post(params) messages.success(request, "Group `{}` created sucessfully.".format(params.get("name"))) except HttpClientError: diff --git a/ipynbsrv/web/views/containers.py b/ipynbsrv/web/views/containers.py index 524204d..2ee88f5 100644 --- a/ipynbsrv/web/views/containers.py +++ b/ipynbsrv/web/views/containers.py @@ -99,10 +99,6 @@ def create(request): if image: try: - # does not make any sense, but seems like it won't work without this line - # Todo: find the actual problem! - client.containers.get() - # server and owner get set by the core automatically client.containers.post(params) messages.success(request, "Image created successfully.") diff --git a/ipynbsrv/web/views/shares.py b/ipynbsrv/web/views/shares.py index 48f1d60..5a32505 100644 --- a/ipynbsrv/web/views/shares.py +++ b/ipynbsrv/web/views/shares.py @@ -61,7 +61,6 @@ def create(request): # create a new tag try: tag_params = {"label": str(tag)} - t = client.tags.get() t = client.tags.post(tag_params) except Exception as e: messages.error(request, api_error_message(e, tag_params)) @@ -105,8 +104,6 @@ def share_add_access_groups(request): params = {} params['access_groups'] = access_groups - # then call API to add the users to the group - client.shares.get() try: client.shares(share_id).add_access_groups.post(params) messages.success(request, "The selected groups are now a member of this share.") From 318d293feeda8d25f8f908b78e406216d872b217 Mon Sep 17 00:00:00 2001 From: Christian Glatthard Date: Mon, 10 Aug 2015 10:40:22 +0200 Subject: [PATCH 2/2] add try catch around get image --- ipynbsrv/web/views/containers.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ipynbsrv/web/views/containers.py b/ipynbsrv/web/views/containers.py index 2ee88f5..496908f 100644 --- a/ipynbsrv/web/views/containers.py +++ b/ipynbsrv/web/views/containers.py @@ -28,7 +28,11 @@ def clone(request): new_name = "{}_clone".format(container.name) # create clone - client.containers(ct_id).clone.post({"name": new_name}) + try: + client.containers(ct_id).clone.post({"name": new_name}) + messages.success(request, "Sucessfully created the clone `{}`.".format(new_name)) + except Exception as e: + messages.error(request, api_error_message(e, params)) return redirect('containers') @@ -96,6 +100,8 @@ def create(request): image = client.containers.images(params.get('image_id')).get() except HttpNotFoundError: messages.error(request, "Container bootstrap image does not exist or you don't have enough permissions for the requested operation.") + except Exception as ex: + messages.error(request, api_error_message(ex, params)) if image: try: