From 4ffe03690aff813d103a34ed084ae79c4a9dee72 Mon Sep 17 00:00:00 2001 From: Yasin Date: Tue, 8 Jul 2014 12:48:31 +0200 Subject: [PATCH] Slicereq view and template fix --- portal/slicerequestview.py | 29 +++++++++--- .../onelab/onelab_slicerequest_view.html | 45 ++++++++++++------- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/portal/slicerequestview.py b/portal/slicerequestview.py index 03b42ae0..abc9a3a9 100644 --- a/portal/slicerequestview.py +++ b/portal/slicerequestview.py @@ -38,10 +38,19 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): if authorities is not None: authorities = sorted(authorities) - # Get user_hrn (XXX Would deserve to be simplified) - user_query = Query().get('local:user').select('email') - user_emails = execute_query(wsgi_request, user_query) - user_email = user_emails[0].get('email') + # Get user_email (XXX Would deserve to be simplified) + user_query = Query().get('local:user').select('email','config') + user_details = execute_query(wsgi_request, user_query) + user_email = user_details[0].get('email') + # getting user_hrn + for user_detail in user_details: + user_config = json.loads(user_detail['config']) + user_authority = user_config.get('authority','N/A') + # getting the org from authority + for authority in authorities: + if authority['authority_hrn'] == user_authority: + authority_name = authority['name'] + # account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') account_details = execute_query(wsgi_request, account_query) @@ -79,6 +88,13 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): # get the domain url current_site = Site.objects.get_current() current_site = current_site.domain + + # getting the authority_hrn from the selected organization + for authority in authorities: + if authority['name'] == wsgi_request.POST.get('org_name', ''): + authority_hrn = authority['authority_hrn'] + + slice_request = { 'type' : 'slice', @@ -86,7 +102,7 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): 'user_hrn' : user_hrn, 'email' : user_email, 'timestamp' : time.time(), - 'authority_hrn' : wsgi_request.POST.get('authority_hrn', ''), + 'authority_hrn' : authority_hrn, 'slice_name' : wsgi_request.POST.get('slice_name', ''), 'number_of_nodes' : wsgi_request.POST.get('number_of_nodes', ''), 'purpose' : wsgi_request.POST.get('purpose', ''), @@ -126,7 +142,8 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): 'errors': errors, 'email': user_email, 'user_hrn': user_hrn, - 'pi': pi, + 'pi': pi, + 'authority_name': authority_name, 'cc_myself': True, 'authorities': authorities, 'theme': self.theme, diff --git a/portal/templates/onelab/onelab_slicerequest_view.html b/portal/templates/onelab/onelab_slicerequest_view.html index ef0ca28f..5d0cf56e 100644 --- a/portal/templates/onelab/onelab_slicerequest_view.html +++ b/portal/templates/onelab/onelab_slicerequest_view.html @@ -35,11 +35,11 @@
{%if 'is_pi' in pi %} - {%else%} - + {%endif%}
@@ -61,21 +61,34 @@ jQuery(document).ready(function(){ $("#authority_hrn").load("/rest/user/", {"fields" : ["parent_authority"], "filters": {"user_hrn": "{{ user_hrn }}"}}, function(data) { var jsonData = JSON.parse(data); - $(this).attr("value", jsonData[0]['parent_authority']); + // getting the authority from the view not rest + $(this).attr("value", "{{authority_name}}"); }); - var availableTags = [ - {% if authorities %} - {% for authority in authorities %} - {% if authority.name %} - {value:"{{ authority.authority_hrn }}",label:"{{authority.name}}"}, - {% else %} - {value:"{{ authority.authority_hrn }}",label:"{{authority.authority_hrn}}"}, - {% endif %} - {% endfor %} - {% else %} - {value:"",label:"No authority found !!!"} - {% endif %} + var availableTags = [ + {% if authorities %} + {% for authority in authorities %} + {% if authority.name %} + {value:"{{ authority.name }}",label:"{{authority.name}}"}, + // to show only full name + // {% else %} + // {value:"{{ authority.authority_hrn }}",label:"{{authority.authority_hrn}}"}, + {% endif %} + {% endfor %} + {% else %} + {value:"",label:"No authority found !!!"} + {% endif %} ]; + // sorting the list + availableTags.sort(function(a,b){ + var nameA=a.value.toLowerCase(), nameB=b.value.toLowerCase(); + if (nameA < nameB) { + return -1; + } + if (nameA > nameB) { + return 1; + } + return 0; + }); $( "#authority_hrn" ).autocomplete({ source: availableTags, minLength: 0, -- 2.43.0