From a3ac89597a0423568ad4cb659111b277683134bc Mon Sep 17 00:00:00 2001 From: Thierry Parmentelat Date: Mon, 2 Sep 2013 12:35:36 +0200 Subject: [PATCH] I found myself in a context where 'config' was not set probably because I'm using a pre-existing account or something --- portal/views.py | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/portal/views.py b/portal/views.py index de7a5ac8..bcb72412 100644 --- a/portal/views.py +++ b/portal/views.py @@ -612,6 +612,8 @@ class AccountView(TemplateView): user_query = Query().get('local:user').select('config','email') user_details = execute_query(self.request, user_query) + # not always found in user_details... + config={} for user_detail in user_details: #email = user_detail['email'] if user_detail['config']: @@ -634,16 +636,9 @@ class AccountView(TemplateView): 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') #page.enqueue_query(network_query) @@ -663,10 +658,10 @@ class AccountView(TemplateView): 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'] - 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 @@ -676,7 +671,7 @@ class AccountView(TemplateView): context['topmenu_items'] = topmenu_items('My Account', self.request) # so we can sho who is logged context['username'] = the_user(self.request) - context ['firstname'] = config['firstname'] +# context ['firstname'] = config['firstname'] #context.update(page.prelude_env()) return context -- 2.43.0