From a91d0326c90ffbcd1c802f0a56498c3638cb1adf Mon Sep 17 00:00:00 2001 From: lombardofr Date: Sun, 19 May 2019 13:24:36 +0200 Subject: [PATCH] fix error propagation in userhandler Change-Id: I39d846373f0068b548a6721a9e277efcf258c6a9 Signed-off-by: lombardofr --- static/src/userhandler/user_list.js | 2 +- userhandler/templates/user_list.html | 40 ++++++++++++++++++++++++++-- userhandler/views.py | 17 ++++++++---- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/static/src/userhandler/user_list.js b/static/src/userhandler/user_list.js index 615f118..9a52249 100644 --- a/static/src/userhandler/user_list.js +++ b/static/src/userhandler/user_list.js @@ -84,7 +84,7 @@ function deleteUser(user_id, name) { success: function (result) { //$('#modal_show_vim_body').empty(); dialog.modal('hide'); - location.reload(); + table.ajax.reload(); }, error: function (result) { dialog.modal('hide'); diff --git a/userhandler/templates/user_list.html b/userhandler/templates/user_list.html index 87753c6..99393b5 100644 --- a/userhandler/templates/user_list.html +++ b/userhandler/templates/user_list.html @@ -74,8 +74,9 @@ diff --git a/userhandler/views.py b/userhandler/views.py index 47e4302..0c12a84 100644 --- a/userhandler/views.py +++ b/userhandler/views.py @@ -46,10 +46,12 @@ def create(request): "password": request.POST['password'], "projects": request.POST.getlist('projects') } - result = client.user_create(user.get_token(), user_data) - - return __response_handler(request, result, 'users:list', to_redirect=True) + if result['error']: + return __response_handler(request, result['data'], url=None, + status=result['data']['status'] if 'status' in result['data'] else 500) + else: + return __response_handler(request, {}, url=None, status=200) @login_required @@ -57,10 +59,15 @@ def delete(request, user_id=None): user = osmutils.get_user(request) try: client = Client() - del_res = client.user_delete(user.get_token(), user_id) + result = client.user_delete(user.get_token(), user_id) except Exception as e: log.exception(e) - return __response_handler(request, {}, 'users:list', to_redirect=True, ) + result = {'error': True, 'data': str(e)} + if result['error']: + return __response_handler(request, result['data'], url=None, + status=result['data']['status'] if 'status' in result['data'] else 500) + else: + return __response_handler(request, {}, url=None, status=200) @login_required def update(request, user_id=None): -- 2.25.1