Merge branch 'fibre' of ssh://git.onelab.eu/git/myslice into fibre
[unfold.git] / portal / manageuserview.py
index c5cda1d..52a69da 100644 (file)
@@ -10,8 +10,7 @@ from ui.topmenu                         import topmenu_items_live, the_user
 from django.http                        import HttpResponse, HttpResponseRedirect
 from django.contrib                     import messages
 from django.contrib.auth.decorators     import login_required
-from django.core.mail                   import send_mail
-from theme import ThemeView
+from myslice.theme import ThemeView
 #
 import json, os, re, itertools
 
@@ -25,8 +24,8 @@ class UserView(LoginRequiredAutoLogoutView, ThemeView):
     def get_context_data(self, **kwargs):
 
         page = Page(self.request)
-        page.add_js_files  ( [ "js/jquery.validate.js", "js/my_account.register.js", "js/my_account.edit_profile.js" ] )
-        page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css" ] )
+        page.add_js_files  ( [ "js/jquery.validate.js", "js/my_account.register.js", "js/my_account.edit_profile.js", "js/jquery-ui.js" ] )
+        page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css","css/jquery-ui.css" ] )
 
         for key, value in kwargs.iteritems():
             #print "%s = %s" % (key, value)
@@ -97,10 +96,11 @@ class UserView(LoginRequiredAutoLogoutView, ThemeView):
             for account_detail in account_details:
                 if platform_detail['platform_id'] == account_detail['platform_id']:
                     platform_name = platform_detail['platform']
-                    account_config = json.loads(account_detail['config'])
-                    account_usr_hrn = account_config.get('user_hrn','N/A')
-                    account_pub_key = account_config.get('user_public_key','N/A')
-                    account_reference = account_config.get ('reference_platform','N/A')
+                    if 'config' in account_detail and account_detail['config'] is not '':
+                        account_config = json.loads(account_detail['config'])
+                        account_usr_hrn = account_config.get('user_hrn','N/A')
+                        account_pub_key = account_config.get('user_public_key','N/A')
+                        account_reference = account_config.get ('reference_platform','N/A')
                     # credentials of myslice platform
                     if 'myslice' in platform_detail['platform']:
                         acc_user_cred = account_config.get('delegated_user_credential','N/A')
@@ -261,42 +261,37 @@ def user_process(request, **kwargs):
                     account_config = json.loads(account_detail['config'])
                     acc_slice_cred = account_config.get('delegated_slice_credentials','N/A')
                     acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
-                
-
                     
-    
-    # adding the slices and corresponding credentials to list
-    if 'N/A' not in acc_slice_cred:
-        slice_list = []
-        slice_cred = [] 
-        for key, value in acc_slice_cred.iteritems():
-            slice_list.append(key)       
-            slice_cred.append(value)
-        # special case: download each slice credentials separately 
-        for i in range(0, len(slice_list)):
-            if 'dl_'+slice_list[i] in request.POST:
-                slice_detail = "Slice name: " + slice_list[i] +"\nSlice Credentials: \n"+ slice_cred[i]
-                response = HttpResponse(slice_detail, content_type='text/plain')
-                response['Content-Disposition'] = 'attachment; filename="slice_credential.txt"'
-                return response
-
-    # adding the authority and corresponding credentials to list
-    if 'N/A' not in acc_auth_cred:
-        auth_list = []
-        auth_cred = [] 
-        for key, value in acc_auth_cred.iteritems():
-            auth_list.append(key)       
-            auth_cred.append(value)
-        # special case: download each slice credentials separately
-        for i in range(0, len(auth_list)):
-            if 'dl_'+auth_list[i] in request.POST:
-                auth_detail = "Authority: " + auth_list[i] +"\nAuthority Credentials: \n"+ auth_cred[i]
-                response = HttpResponse(auth_detail, content_type='text/plain')
-                response['Content-Disposition'] = 'attachment; filename="auth_credential.txt"'
-                return response
-
-
-             
+                    # adding the slices and corresponding credentials to list
+                    if 'N/A' not in acc_slice_cred:
+                        slice_list = []
+                        slice_cred = [] 
+                        for key, value in acc_slice_cred.iteritems():
+                            slice_list.append(key)       
+                            slice_cred.append(value)
+                        # special case: download each slice credentials separately 
+                        for i in range(0, len(slice_list)):
+                            if 'dl_'+slice_list[i] in request.POST:
+                                slice_detail = "Slice name: " + slice_list[i] +"\nSlice Credentials: \n"+ slice_cred[i]
+                                response = HttpResponse(slice_detail, content_type='text/plain')
+                                response['Content-Disposition'] = 'attachment; filename="slice_credential.txt"'
+                                return response
+
+                    # adding the authority and corresponding credentials to list
+                    if 'N/A' not in acc_auth_cred:
+                        auth_list = []
+                        auth_cred = [] 
+                        for key, value in acc_auth_cred.iteritems():
+                            auth_list.append(key)       
+                            auth_cred.append(value)
+                        # special case: download each slice credentials separately
+                        for i in range(0, len(auth_list)):
+                            if 'dl_'+auth_list[i] in request.POST:
+                                auth_detail = "Authority: " + auth_list[i] +"\nAuthority Credentials: \n"+ auth_cred[i]
+                                response = HttpResponse(auth_detail, content_type='text/plain')
+                                response['Content-Disposition'] = 'attachment; filename="auth_credential.txt"'
+                                return response
+
     if 'submit_name' in request.POST:
         edited_first_name =  request.POST['fname']
         edited_last_name =  request.POST['lname']
@@ -404,7 +399,7 @@ def user_process(request, **kwargs):
                             return HttpResponseRedirect(redirect_url)
         else:
             messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
-            return HttpResponseRedirect("/portal/account/")
+            return HttpResponseRedirect(redirect_url)
 
     elif 'dl_pubkey' in request.POST:
         for account_detail in account_details:
@@ -438,7 +433,7 @@ def user_process(request, **kwargs):
 
         else:
             messages.error(request, 'Account error: You need an account in myslice platform to perform this action')
-            return HttpResponseRedirect("/portal/account/")
+            return HttpResponseRedirect(redirect_url)
     
 #    elif 'delete' in request.POST:
 #        for account_detail in account_details:
@@ -481,7 +476,7 @@ def user_process(request, **kwargs):
                             user_params = { 'config': updated_config}
                             manifold_update_account(request, user_id,user_params)
                             messages.success(request, 'All Credentials cleared')
-                            return HttpResponseRedirect("/portal/account/")
+                            return HttpResponseRedirect(redirect_url)
                         else:
                             messages.error(request, 'Delete error: Credentials are not stored in the server')
                             return HttpResponseRedirect(redirect_url)