From: Ciro Scognamiglio Date: Tue, 27 Jan 2015 17:43:26 +0000 (+0100) Subject: Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab X-Git-Tag: myslice-1.3~98 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=5c6d3dfae3a4aed1a18a9f1a946655631328351d;p=myslice.git Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab Conflicts: portal/actions.py portal/static/js/myslice.js --- 5c6d3dfae3a4aed1a18a9f1a946655631328351d diff --cc .settings/org.eclipse.core.resources.prefs index f73c991a,f73c991a..dad90097 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@@ -2,7 -2,7 +2,10 @@@ eclipse.preferences.version= encoding//portal/django_passresetview.py=utf-8 encoding//portal/forms.py=utf-8 encoding//portal/migrations/0002_extend_slice.py=utf-8 ++encoding//portal/migrations/0005_extend_user.py=utf-8 ++encoding//portal/migrations/0008_extend_user.py=utf-8 ++encoding//portal/migrations/0009_initial.py=utf-8 ++encoding//portal/migrations/0010_project.py=utf-8 encoding//portal/models.py=utf-8 encoding//portal/urls.py=utf-8 encoding//portal/validationview.py=utf-8 --encoding//portal/views.py=utf-8 diff --cc myslice/settings.py index bd1474bd,bd1474bd..3b1f1f3d --- a/myslice/settings.py +++ b/myslice/settings.py @@@ -47,7 -47,7 +47,7 @@@ except # assume we have ./static present already HTTPROOT="/var/myslice-f4f" # the place to store local data, like e.g. the sqlite db --DATAROOT="/var/unfold" ++DATAROOT="/Users/moray/Sites/upmc/myslice" # if not there, then we assume it's from a devel tree if not os.path.isdir (os.path.join(HTTPROOT,"static")): HTTPROOT=ROOT diff --cc portal/actions.py index 5b72d646,90f7db9b..9018fbf3 --- a/portal/actions.py +++ b/portal/actions.py @@@ -1,17 -1,19 +1,19 @@@ - from django.http import HttpResponse - from manifold.core.query import Query - from manifoldapi.manifoldapi import execute_query,execute_admin_query - from portal.models import PendingUser, PendingSlice, PendingAuthority, PendingProject + from django.http import HttpResponse + from manifold.core.query import Query + from manifoldapi.manifoldapi import execute_query,execute_admin_query -from portal.models import PendingUser, PendingSlice, PendingAuthority ++from portal.models import PendingUser, PendingSlice, PendingAuthority, PendingProject + from unfold.page import Page + import json - from django.contrib.auth.models import User - from django.contrib.sites.models import Site - from django.contrib.auth import get_user_model - from django.template.loader import render_to_string - from django.core.mail import EmailMultiAlternatives, send_mail + from django.contrib.auth.models import User + from django.contrib.sites.models import Site + from django.contrib.auth import get_user_model + from django.template.loader import render_to_string + from django.core.mail import EmailMultiAlternatives, send_mail - from myslice.theme import ThemeView - from myslice.configengine import ConfigEngine + from myslice.theme import ThemeView + from myslice.configengine import ConfigEngine theme = ThemeView() diff --cc portal/models.py index cc484b5b,cc484b5b..6670c4c0 --- a/portal/models.py +++ b/portal/models.py @@@ -96,3 -96,3 +96,10 @@@ class PendingSlice(models.Model) type_of_nodes = models.TextField(default='NA') purpose = models.TextField(default='NA') created = models.DateTimeField(auto_now_add = True) ++ ++class PendingProject(models.Model): ++ project_name = models.TextField() ++ user_hrn = models.TextField() ++ authority_hrn = models.TextField(null=True) ++ purpose = models.TextField(default='NA') ++ created = models.DateTimeField(auto_now_add = True) diff --cc portal/projectrequestview.py index d2f11a6a,d2f11a6a..70f49949 --- a/portal/projectrequestview.py +++ b/portal/projectrequestview.py @@@ -1,35 -1,35 +1,132 @@@ from django.shortcuts import render 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 --#from portal.forms import SliceRequestForm from unfold.loginrequired import LoginRequiredAutoLogoutView --from ui.topmenu import topmenu_items_live, the_user ++ ++from portal.actions import create_pending_project ++ ++from portal.models import PendingProject from myslice.theme import ThemeView import json, time, re --import activity.user -- --class ProjectRequestView (LoginRequiredAutoLogoutView, ThemeView): ++class ProjectRequestView(LoginRequiredAutoLogoutView, ThemeView): template_name = 'projectrequest_view.html' -- # because we inherit LoginRequiredAutoLogoutView that is implemented by redefining 'dispatch' -- # we cannot redefine dispatch here, or we'd lose LoginRequired and AutoLogout behaviours -- def post (self, request): -- return self.get_or_post (request, 'POST') ++ def getAuthorities(self, request): ++ 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']) ++ return authorities ++ ++ def getUserAuthority(self, request): ++ # Get user_email (XXX Would deserve to be simplified) ++ user_query = Query().get('local:user').select('email','config') ++ user_details = execute_query(request, user_query) ++ for user_detail in user_details: ++ user_config = json.loads(user_detail['config']) ++ user_authority = user_config.get('authority','N/A') ++ return user_authority ++ ++ def getUserHrn(self, request): ++ user_hrn = None ++ ++ account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config') ++ account_details = execute_query(request, account_query) ++ ++ platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled') ++ platform_details = execute_query(request, platform_query) ++ ++ # getting user_hrn from local:account ++ for account_detail in account_details: ++ for platform_detail in platform_details: ++ if platform_detail['platform_id'] == account_detail['platform_id']: ++ # taking user_hrn only from myslice account ++ # NOTE: we should later handle accounts filter_by auth_type= managed OR user ++ if 'myslice' in platform_detail['platform']: ++ account_config = json.loads(account_detail['config']) ++ user_hrn = account_config.get('user_hrn','N/A') ++ return user_hrn ++ ++ def post(self, request): ++ return self.handle_request(request, 'POST') -- def get (self, request): -- return self.get_or_post (request, 'GET') ++ def get(self, request): ++ return self.handle_request(request, 'GET') -- def get_or_post (self, wsgi_request, method): ++ def handle_request(self, wsgi_request, method): ++ errors = [] ++ authority_hrn = None ++ authority_name = None ++ ++ user_hrn = self.getUserHrn(wsgi_request) ++ ++ authorities = self.getAuthorities(wsgi_request) ++ ++ user_authority = self.getUserAuthority(wsgi_request) ++ ++ # getting the org from authority ++ for authority in authorities: ++ if authority['authority_hrn'] == user_authority: ++ authority_name = authority['name'] ++ ++ if method == 'POST' : ++ ++ post = { ++ 'user_hrn' : user_hrn, ++ 'authority_hrn' : wsgi_request.POST.get('authority_name', ''), ++ 'project_name' : wsgi_request.POST.get('project_name', ''), ++ 'purpose' : wsgi_request.POST.get('purpose', ''), ++ } ++ ++# # create slice_hrn based on authority_hrn and slice_name ++# # slice_name = slice_request['slice_name'] ++# req_slice_hrn = authority_hrn + '.' + slice_name ++# # comparing requested slice_hrn with the existing slice_hrn ++# slice_query = Query().get('myslice:slice').select('slice_hrn','parent_authority').filter_by('parent_authority','==',authority_hrn) ++# slice_details_sfa = execute_admin_query(wsgi_request, slice_query) ++# for _slice in slice_details_sfa: ++# if _slice['slice_hrn'] == req_slice_hrn: ++# errors.append('Slice already exists. Please use a different slice name.') ++ ++ ++ # What kind of slice name is valid? ++ if (post['project_name'] is None or post['project_name'] == ''): ++ errors.append('Project name is mandatory') ++ ++ if (re.search(r'^[A-Za-z0-9_]*$', post['project_name']) == None): ++ errors.append('Project name may contain only letters, numbers, and underscore.') ++ ++ if (post['authority_hrn'] is None or post['authority_hrn'] == ''): ++ errors.append('Organization is mandatory') ++ ++ if (post['purpose'] is None or post['purpose'] == ''): ++ errors.append('Experiment purpose is mandatory') ++ ++ if not errors: ++ create_pending_project(wsgi_request, post) ++ ++ # retrieves the pending projects list ++ pending_projects = PendingProject.objects.all().filter(user_hrn=user_hrn) ++ ++ env = { ++ 'errors': errors, ++ 'username': wsgi_request.user, ++ 'theme': self.theme, ++ 'authorities': authorities, ++ 'authority_hrn': user_authority, ++ 'pending_projects': pending_projects, ++ } ++ return render(wsgi_request, self.template, env) ++ ++ ++ """ """ errors = [] @@@ -67,6 -67,6 +164,7 @@@ # platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled') platform_details = execute_query(wsgi_request, platform_query) ++ user_hrn = None # getting user_hrn from local:account for account_detail in account_details: @@@ -88,17 -88,17 +186,17 @@@ # Page rendering -- page = Page(wsgi_request) -- page.add_js_files ( [ "js/jquery.validate.js", "js/jquery-ui.js" ] ) -- page.add_css_files ( [ "https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" ] ) -- page.expose_js_metadata() ++# page = Page(wsgi_request) ++# page.add_js_files ( [ "js/jquery.validate.js", "js/jquery-ui.js" ] ) ++# page.add_css_files ( [ "https://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" ] ) ++# page.expose_js_metadata() if method == 'POST': # The form has been submitted # get the domain url -- current_site = Site.objects.get_current() -- current_site = current_site.domain ++# current_site = Site.objects.get_current() ++# current_site = current_site.domain # getting the authority_hrn from the selected organization for authority in authorities: @@@ -124,7 -124,7 +222,7 @@@ } # create slice_hrn based on authority_hrn and slice_name -- slice_name = slice_request['slice_name'] ++# slice_name = slice_request['slice_name'] req_slice_hrn = authority_hrn + '.' + slice_name # comparing requested slice_hrn with the existing slice_hrn slice_query = Query().get('myslice:slice').select('slice_hrn','parent_authority').filter_by('parent_authority','==',authority_hrn) @@@ -173,7 -173,7 +271,6 @@@ template_env = { 'username': wsgi_request.user.email, -- 'topmenu_items': topmenu_items_live('Request a slice', page), 'errors': errors, 'slice_name': slice_name, 'purpose': purpose, diff --cc portal/static/css/fed4fire.css index 987d54e5,987d54e5..ca827bf4 --- a/portal/static/css/fed4fire.css +++ b/portal/static/css/fed4fire.css @@@ -31,6 -31,6 +31,20 @@@ h3 color:#201E62; } ++input[type=text], input[type=password], input[type=email], input[type=tel], input[type=number] { ++ min-width:260px; ++ padding:6px; ++ border:1pt solid #CCCCCC; ++ vertical-align:bottom; ++ border-radius:0; ++} ++ ++textarea { ++ padding:6px; ++ border:1pt solid #CCCCCC !important; ++ border-radius:0 !important; ++} ++ div.wrapper { width:980px; margin:0 auto; diff --cc portal/static/js/myslice.js index fcde9672,4fe42dae..548d5dab --- a/portal/static/js/myslice.js +++ b/portal/static/js/myslice.js @@@ -187,36 -210,7 +210,8 @@@ var myslice = } }, - loadProjects: function(fn) { - var u = localStorage.getItem('user'); - if (u !== 'undefined') { - var user = JSON.parse(u); - var projects = localStorage.getItem('projects'); - if($.isEmptyObject(projects)){ - if($.isEmptyObject(user) || $.isEmptyObject(user.parent_authority)){ - $.post("/rest/myslice:user/",{'filters':{'user_hrn':'$user_hrn'},'fields':['parent_authority']}, function( data ) { - parent_authority = data[0].parent_authority; - - }); - }else{ - parent_authority = user.parent_authority; - } - // REGISTRY ONLY TO BE REMOVED WITH MANIFOLD-V2 - $.post("/rest/myslice:authority/",{'fields':['authority_hrn'],'filters':{'authority_hrn':'CONTAINS'+parent_authority}}, function( data ) { - localStorage.setItem('projects', JSON.stringify(data)); - if(isFunction(fn)){ - fn(); - } - }); - }else{ - if(isFunction(fn)){ - fn(); - } - } - } - }, + getSlices: function(name) { }, diff --cc portal/templates/_widget-slice-sections.html index 175b09c0,175b09c0..0856bd89 --- a/portal/templates/_widget-slice-sections.html +++ b/portal/templates/_widget-slice-sections.html @@@ -4,7 -4,7 +4,7 @@@
  • Testbeds
  • Resources
  • Users
  • -- ++
  • Statistics
  • Measurements
  • Experiment
  • SLA
  • @@@ -15,7 -15,7 +15,7 @@@
  • Testbeds
  • Resources
  • Users
  • -- ++
  • Statistics
  • Measurements
  • Experiment
  • SLA
  • diff --cc portal/templates/fed4fire/fed4fire_projectrequest_view.html index 962976fc,962976fc..a4c433bc --- a/portal/templates/fed4fire/fed4fire_projectrequest_view.html +++ b/portal/templates/fed4fire/fed4fire_projectrequest_view.html @@@ -2,68 -2,68 +2,126 @@@ {% load i18n %} {% block content %} --
    --
    -- --
    --
    ++
    ++
    ++ ++
    -- {% if errors %} --
    --
    --
      -- {% for error in errors %} --
    • {{ error }}
    • -- {% endfor %} --
    --
    --
    -- {% endif %} -- --
    --
    --
    -- {% csrf_token %} -- --
    -- --
    --
    -- New Project --
    --
    -- Existing Project --
    --
    -- --
    -- {%if 'is_pi' in pi %} -- -- {%else%} -- -- {%endif%} --
    -- --
    --
    ++{% if errors %} ++
    ++
    ++
      ++ {% for error in errors %} ++
    • {{ error }}
    • ++ {% endfor %} ++
    ++
    ++
    ++{% endif %} ++ ++
    ++ ++
    ++
    ++
    ++

    Join an existing Project

    ++
    ++
    ++

    List of projects you are part of

    ++
    ++
    ++
    ++
    ++
    ++ {% csrf_token %} ++ ++
    ++
    ++
    ++ ++ {% for pending in pending_projects %} ++ ++ {% endfor %} ++
    (PENDING) {{ pending.project_name }}{{ pending.authority_hrn }}{{ pending.created|date:"d/m/Y" }}
    ++
    ++
    ++
    ++ ++
    ++
    ++
    ++

    Create a new Project

    ++
    ++
    ++ ++ ++
    ++
    ++
    ++ {% csrf_token %} ++
    ++ ++
    ++
    ++ ++
    ++ ++ ++
    ++ ++
    ++ ++
    ++ ++
    ++
    ++
    ++ ++
    diff --cc portal/templates/management-tab-requests.html index dad0e6e7,dad0e6e7..dd3ce14f --- a/portal/templates/management-tab-requests.html +++ b/portal/templates/management-tab-requests.html @@@ -139,6 -139,6 +139,8 @@@ {{request.first_name}} {{request.last_name}} <{{request.email}}> {% elif request.type == 'slice' %} {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}} ++ {% elif request.type == 'project' %} ++ {{request.project_name}} -- {{ request.user_hrn }} -- Purpose: {{request.purpose}} {% else %} {{request.site_name}} ({{request.site_authority}}) -- {{request.address_city}}, {{request.address_country}} {% endif %} @@@ -201,6 -201,6 +203,8 @@@ {% else %} {% if request.type == 'slice' %} Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}} ++ {% elif request.type == 'project' %} ++ {{request.project_name}} -- {{ request.user_hrn }} -- Purpose: {{request.purpose}} {% else %} {# authority #} Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}} {% endif %} @@@ -255,6 -255,6 +259,8 @@@ {% else %} {% if request.type == 'slice' %} Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}} ++ {% elif request.type == 'project' %} ++ {{request.project_name}} -- {{ request.user_hrn }} -- Purpose: {{request.purpose}} {% else %} {# authority #} Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}} {% endif %} diff --cc portal/templates/slice-resource-view.html index ff1fc3e0,ff1fc3e0..93285e12 --- a/portal/templates/slice-resource-view.html +++ b/portal/templates/slice-resource-view.html @@@ -54,9 -54,9 +54,9 @@@ $(document).ready(function()