FIX: conflict in My Account view. Thanks to thierry for making the code more efficient
authorYasin <mohammed-yasin.rahman@lip6.fr>
Mon, 2 Sep 2013 15:54:30 +0000 (17:54 +0200)
committerYasin <mohammed-yasin.rahman@lip6.fr>
Mon, 2 Sep 2013 15:54:30 +0000 (17:54 +0200)
1  2 
portal/views.py

diff --cc portal/views.py
@@@ -637,35 -635,33 +639,27 @@@ class AccountView(TemplateView)
                      platform_name = platform_detail['platform']
                      account_type = account_detail['auth_type']
                      account_config = json.loads(account_detail['config'])
--                    
-                     if 'user_hrn' in account_config:
-                         account_usr_hrn = account_config['user_hrn']
-                     else:
-                         account_usr_hrn = 'N/A'
-                     if 'user_public_key' in account_config:
-                         account_pub_key = account_config['user_public_key']
-                     else:
-                         account_pub_key = 'N/A'            
-                         #print "THis is a test"
-                         #print account_pub_key
+                     # a bit more pythonic
+                     account_usr_hrn = account_config.get('user_hrn','N/A')
+                     account_pub_key = account_config.get('user_public_key','N/A')
 +                    
 +                    platform_name_list.append(platform_name)
 +                    account_type_list.append(account_type)
 +                    usr_hrn_list.append(account_usr_hrn)
 +                    pub_key_list.append(account_pub_key)
          
 -        #page.enqueue_query(network_query)
 -
 -        #page.expose_js_metadata()
 -        #page.expose_queries()
 -
 -        #userlist = SimpleList(
 -        #    title = None,
 -        #    page  = page,
 -        #    key   = 'user_id',
 -        #    query = network_query,
 -        #)
 +        # combining 4 lists into 1 [to render in the template] 
 +        lst = [{'platform_name': t[0], 'account_type': t[1], 'usr_hrn':t[2], 'usr_pubkey':t[3]} for t in zip(platform_name_list, account_type_list, usr_hrn_list, pub_key_list)]    
 +        #print "test"
 +        #print lst
  
          context = super(AccountView, self).get_context_data(**kwargs)
 -        context['platform_name'] = platform_name
 -        context['account_type'] = account_type
 -        context['account_usr_hrn'] = account_usr_hrn
 -        context['account_pub_key'] = account_pub_key 
 +        context['data'] = lst
          context['person']   = self.request.user
-         context ['fullname'] = config['firstname'] +' '+ config['lastname']    
-         context ['firstname'] = config['firstname']
-         context ['lastname'] = config['lastname']
-         context ['affiliation'] = config['affiliation']
+         context ['firstname'] = config.get('firstname',"?")
+         context ['lastname'] = config.get('lastname',"?")
+         context ['fullname'] = context['firstname'] +' '+ context['lastname']
+         context ['affiliation'] = config.get('affiliation',"Unknown Affiliation")
          #context['users'] = userlist.render(self.request)
          
          # XXX This is repeated in all pages