Removes metric and alarm operations from NS instance actions
[osm/LW-UI.git] / userhandler / views.py
index a7c014d..0c12a84 100644 (file)
@@ -1,3 +1,19 @@
+#
+#   Copyright 2018 EveryUP Srl
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an  BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+#
+
 from django.shortcuts import render, redirect
 from sf_t3d.decorators import login_required
 from django.http import HttpResponse
@@ -30,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
@@ -41,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):