From f214ff223d889b18dd539c3604e6e0ecf7c108fd Mon Sep 17 00:00:00 2001
From: Yasin <mohammed-yasin.rahman@lip6.fr>
Date: Wed, 28 Aug 2013 18:32:05 +0200
Subject: [PATCH] Platform Access added to My Account. for loop in html table
 to be added

---
 portal/templates/my_account.html | 19 ++++++++++++++
 portal/views.py                  | 45 +++++++++++++++++++++++++++-----
 2 files changed, 57 insertions(+), 7 deletions(-)

diff --git a/portal/templates/my_account.html b/portal/templates/my_account.html
index 2970c425..1500ce89 100644
--- a/portal/templates/my_account.html
+++ b/portal/templates/my_account.html
@@ -3,6 +3,7 @@
 {% block head %}
 <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}/css/my_account.common.css" />
 <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}/css/my_account.profile.css" />
+<!-- <link rel="stylesheet" type="text/css" href="{{STATIC_URL}}/css/dashboard.css" /> !-->
 <script type="text/javascript" src="{{STATIC_URL}}/jquery.validate.js"></script> 
 <script type="text/javascript" src="{{STATIC_URL}}/my_account.edit_profile.js"></script>
 <script type="text/javascript" src="{{STATIC_URL}}/my_account.register.js"></script>
@@ -11,6 +12,24 @@
 {% block unfold1_main %}
 
 
+<h2>Platform Access</h2>
+<table border="2" bordercolor="FFCC00" style="table-layout:fixedbackground-color:FFFFCCwidth:830px" cellpadding="12" cellspacing="12"> 
+	<tr> 
+    	<th align="center" style="width:15%">Platform</th> 
+        <th align="center" style="width:15%">Account Type</th> 
+        <th align="center" style="width:15%">user_hrn</th>
+        <th align="center">Pub Key</th>
+    </tr>            
+   	<tr>
+    	<td align="center"> {{ platform_name }} </td>
+        <td align="center"> {{ account_type }} </td>
+       	<td align="center" style="word-wrap: break-word"> {{ account_usr_hrn }}  </td>
+        <td align="center" style="word-wrap: break-word"> {{ account_pub_key }} </td>
+    </tr>                
+</table>
+
+
+
 
 <div class='ms-dashboard-panel' id='ms-dashboard-slices' style=" display:block; float:none"  >
     <div class='ms-dashboard-caption'>
diff --git a/portal/views.py b/portal/views.py
index d4fa22ea..de7a5ac8 100644
--- a/portal/views.py
+++ b/portal/views.py
@@ -609,14 +609,41 @@ class AccountView(TemplateView):
     def get_context_data(self, **kwargs):
         #page = Page(self.request)
 
-        user_query  = Query().get('local:user').select('config')
-        user_accounts = execute_query(self.request, user_query)
+        user_query  = Query().get('local:user').select('config','email')
+        user_details = execute_query(self.request, user_query)
         
-        for user_account in user_accounts:
-            config = json.loads(user_account['config'])
-
-        #print "THis is a test"
-        #print config['firstname'] 
+        for user_detail in user_details:
+            #email = user_detail['email']
+            if user_detail['config']:
+                config = json.loads(user_detail['config'])
+
+        platform_query  = Query().get('local:platform').select('platform_id','platform')
+        account_query  = Query().get('local:account').select('user_id','platform_id','auth_type','config')
+        platform_details = execute_query(self.request, platform_query)
+        account_details = execute_query(self.request, account_query)
+       
+        # initial assignment needed for users having no account  
+        platform_name = ''
+        account_type = ''
+        account_usr_hrn = ''
+        account_pub_key = ''       
+        for account_detail in account_details:
+            for platform_detail in platform_details:
+                if platform_detail['platform_id'] == account_detail['platform_id']:
+                    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
         
         #page.enqueue_query(network_query)
 
@@ -631,6 +658,10 @@ class AccountView(TemplateView):
         #)
 
         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['person']   = self.request.user
         context ['fullname'] = config['firstname'] +' '+ config['lastname']    
         context ['firstname'] = config['firstname']
-- 
2.47.0