X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=portal%2Fslicerequestview.py;h=9ccaf763631338bce1adef319aa5f5f8b6ae4d84;hb=refs%2Fheads%2Fonelab;hp=f9a540aedaabb2e3ae6645a43165c38d2977384d;hpb=3447ca3d4f1d2aa115989433e1032ad07e6611ce;p=myslice.git diff --git a/portal/slicerequestview.py b/portal/slicerequestview.py index f9a540ae..9ccaf763 100644 --- a/portal/slicerequestview.py +++ b/portal/slicerequestview.py @@ -5,14 +5,13 @@ import re from django.shortcuts import render from django.shortcuts import render_to_response from django.template import RequestContext -from django.contrib.sites.models import Site from unfold.page import Page from manifold.core.query import Query from manifoldapi.manifoldapi import execute_admin_query, execute_query -from portal.actions import is_pi, create_slice, create_pending_slice, clear_user_creds, authority_check_pis +from portal.actions import is_pi, create_slice, create_pending_slice, clear_user_creds, authority_check_pis, getAuthorities #from portal.forms import SliceRequestForm from unfold.loginrequired import LoginRequiredAutoLogoutView from ui.topmenu import topmenu_items_live, the_user @@ -40,19 +39,23 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): errors = [] slice_name ='' - purpose='' - url='' + #purpose='' + #url='' authority_hrn = None authority_name = None # Retrieve the list of authorities - if self.theme == 'fed4fire': - authorities_query = Query.get('myslice:authority').select('name', 'authority_hrn') - else: - authorities_query = Query.get('authority').select('name', 'authority_hrn') - authorities = execute_admin_query(request, authorities_query) - if authorities is not None: - authorities = sorted(authorities, key=lambda k: k['authority_hrn']) - authorities = sorted(authorities, key=lambda k: k['name']) + + authorities = getAuthorities(request, admin=True) + + ##if self.theme == 'fed4fire' or self.theme == 'onelab': + #authorities_query = Query.get('myslice:authority').select('authority_hrn') + ##else: + ## authorities_query = Query.get('authority').select('name', 'authority_hrn') + #authorities = execute_admin_query(request, authorities_query) + #if authorities is not None: + # authorities = sorted(authorities, key=lambda k: k['authority_hrn']) + # #if self.theme != 'fed4fire' or self.theme != 'onelab': + # # authorities = sorted(authorities, key=lambda k: k['name']) # Get user_email (XXX Would deserve to be simplified) user_query = Query().get('local:user').select('email','config') @@ -63,13 +66,13 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): 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'] + # for authority in authorities: + # if 'name' in authority and authority['authority_hrn'] == user_authority: + # authority_name = authority['name'] # Handle the case when we use only hrn and not name - if authority_name is None: - authority_name = user_authority + #if authority_name is None: + # authority_name = user_authority account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') account_details = execute_query(request, account_query) @@ -88,15 +91,7 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): user_hrn = account_config.get('user_hrn','N/A') # acc_auth_cred = account_config.get('delegated_authority_credentials','N/A') - - # checking if pi or not - #if acc_auth_cred == {} or acc_auth_cred == 'N/A': - # pi = "is_not_pi" - #else: - # pi = "is_pi" - - pi = authority_check_pis (request, user_email) - logger.debug("SLICEREQUESTVIEW.PY ----- pi= {}".format(pi)) + pi = request.session['user']['pi'] # Page rendering page = Page(request) @@ -107,24 +102,26 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): if method == 'POST': # The form has been submitted - # 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'] == request.POST.get('org_name', ''): - authority_hrn = authority['authority_hrn'] + if request.is_secure(): + current_site = 'https://' + else: + current_site = 'http://' + current_site += request.META['HTTP_HOST'] + + #if theme.theme != 'fed4fire' or self.theme != 'onelab': + # getting the authority_hrn from the selected organization + # for authority in authorities: + # if authority['name'] == request.POST.get('org_name', ''): + # authority_hrn = authority['authority_hrn'] # Handle the case when we use only hrn and not name if authority_hrn is None: authority_hrn = request.POST.get('org_name', '') # Handle project if used - project = request.POST.get('project', None) + project = request.POST.get('org_name', None) if project is not None and project != '': authority_hrn = project - slice_name = request.POST.get('slice_name', '') if not slice_name or len(slice_name) == 0 : errors.append('Slice name can\'t be empty') @@ -141,8 +138,8 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): 'authority_hrn' : authority_hrn, 'organization' : request.POST.get('org_name', ''), 'slice_name' : slice_name, - 'url' : request.POST.get('url', ''), - 'purpose' : request.POST.get('purpose', ''), + #'url' : request.POST.get('url', ''), + #'purpose' : request.POST.get('purpose', ''), 'current_site' : current_site } @@ -164,7 +161,7 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): errors.append('Slice name may contain only letters, numbers, and underscore.') organization = slice_request['organization'] - if theme.theme == 'fed4fire': + if theme.theme == 'fed4fire' or self.theme == 'onelab': if organization is None or organization == '': errors.append('Selecting project is mandatory') else: @@ -177,11 +174,11 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): - purpose = slice_request['purpose'] - if purpose is None or purpose == '': - errors.append('Experiment purpose is mandatory') + # purpose = slice_request['purpose'] + # if purpose is None or purpose == '': + # errors.append('Experiment purpose is mandatory') - url = slice_request['url'] + #url = slice_request['url'] if not errors: if is_pi(request, user_hrn, authority_hrn): @@ -206,10 +203,10 @@ class SliceRequestView (LoginRequiredAutoLogoutView, ThemeView): 'topmenu_items': topmenu_items_live('Request a slice', page), 'errors': errors, 'slice_name': slice_name, - 'purpose': purpose, + #'purpose': purpose, 'email': user_email, 'user_hrn': user_hrn, - 'url': url, + #'url': url, 'pi': pi, 'authority_name': authority_name, 'authority_hrn': user_authority,