import logging
import subprocess
+
logger = logging.getLogger('myslice')
# ROOT
else :
theme = None
+if config.myslice.theme_label :
+ theme_label = config.myslice.theme_label
+else :
+ theme_label = theme
+
+if config.myslice.theme_logo :
+ theme_logo = config.myslice.theme_logo
+else :
+ theme_logo = theme + '.png'
+
# HTTPROOT
if config.myslice.httproot :
HTTPROOT = config.myslice.httproot
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = os.path.join(HTTPROOT,'static')
-# URL prefix for static files.
-# Example: "http://media.lawrence.com/static/"
-STATIC_URL = '/static/'
-
# Additional locations of static files
STATICFILES_DIRS = (
# Put strings here, like "/home/html/static" or "C:/www/django/static".
### 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
-#TEMPLATE_CONTEXT_PROCESSORS = (
-# 'django.contrib.auth.context_processors.auth',
-# 'django.core.context_processors.debug',
-# 'django.core.context_processors.i18n',
-# 'django.core.context_processors.media',
-# 'django.core.context_processors.static',
-# 'django.core.context_processors.request',
-# 'django.contrib.messages.context_processors.messages',
-#)
+if config.myslice.secret_key:
+ # Make this unique, and don't share it with anybody.
+ SECRET_KEY = config.myslice.secret_key
+else:
+ raise Exception, "SECRET_KEY Not defined: Please setup a secret_key value in myslice.ini"
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = 't%n(3h)&r^n8(+8)(sp29t^$c2#t(m3)e2!02l8w1#36tl#t27'
+AUTHENTICATION_BACKENDS = ('localauth.manifoldbackend.ManifoldBackend',
+ 'django.contrib.auth.backends.ModelBackend')
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
}
}
-AUTHENTICATION_BACKENDS = ('localauth.manifoldbackend.ManifoldBackend',
- 'django.contrib.auth.backends.ModelBackend')
-
### the view to redirect malformed (i.e. with a wrong CSRF) incoming requests
# without this setting django will return a 403 forbidden error, which is fine
# if you need to see the error message then use this setting
SLA_COLLECTOR_URL = "http://157.193.215.125:4001/sla-collector/sla"
SLA_COLLECTOR_USER = "portal"
SLA_COLLECTOR_PASSWORD = "password"
+
+
+# URL prefix for static files.
+# Example: "http://media.lawrence.com/static/"
+STATIC_URL = '/static/'
+
+
self.config = ConfigEngine()
if self.config.myslice.theme :
return self.config.myslice.theme
-
+
+ @property
+ def label(self):
+ self.config = ConfigEngine()
+ if self.config.myslice.theme_label :
+ return self.config.myslice.theme_label
+
+ @property
+ def logo(self):
+ self.config = ConfigEngine()
+ if self.config.myslice.theme_logo :
+ return self.config.myslice.theme_logo
+
@property
def template(self):
# Load a template from the theme directory if it exists
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 myslice.theme import ThemeView
from myslice.configengine import ConfigEngine
-from myslice.settings import logger
+
+from myslice.settings import logger
theme = ThemeView()
raise Exception, 'unknown type of request %s' % request['type']
# XXX Remove from Pendings in database
- send_status_email(ctx, user_email, request['type'], 'validated')
+ send_status_email(wsgi_request, ctx, user_email, request['type'], 'validated')
except Exception, e:
request_status['SFA '+request['type']] = {'status': False, 'description': str(e)}
json_answer = json.dumps(status)
return HttpResponse (json_answer, content_type="application/json")
+def get_current_site(request):
+ if request.is_secure():
+ current_site = 'https://'
+ else:
+ current_site = 'http://'
+ current_site += request.META['HTTP_HOST']
+ return current_site
def portal_reject_request(wsgi_request, request_ids):
status = {}
- # get the domain url
- current_site = Site.objects.get_current()
- current_site = current_site.domain
-
-
+ current_site = get_current_site(wsgi_request)
if not isinstance(request_ids, list):
request_ids = [request_ids]
else:
raise Exception, 'unknown type of request %s' % request['type']
- send_status_email(ctx, user_email, request['type'], 'denied')
+ send_status_email(wsgi_request, ctx, user_email, request['type'], 'denied')
except Exception, e:
request_status['SFA '+request['type']] = {'status': False, 'description': str(e)}
return status
-def send_status_email(ctx, user_email, obj_type, status):
+def send_status_email(request, ctx, user_email, obj_type, status):
try:
+ ctx['current_site'] = get_current_site(request)
+ ctx['theme'] = theme
+
theme.template_name = obj_type + '_request_' + status + '.txt'
text_content = render_to_string(theme.template, ctx)
theme.template_name = obj_type + '_request_' + status + '.html'
# SEND EMAILS
#-------------------------------------------------------------------------------
-def send_email_to_pis(wsgi_request, request, obj_type):
+def send_email_to_pis(request, context, obj_type):
try:
+ context['current_site'] = get_current_site(request)
+ context['theme'] = theme
# Send an email: the recipients are the PIs of the authority
- recipients = authority_get_pi_emails(wsgi_request, request['authority_hrn'])
+ recipients = authority_get_pi_emails(request, context['authority_hrn'])
theme.template_name = obj_type + '_request_email.txt'
- text_content = render_to_string(theme.template, request)
+ text_content = render_to_string(theme.template, context)
theme.template_name = obj_type + '_request_email.html'
- html_content = render_to_string(theme.template, request)
+ html_content = render_to_string(theme.template, context)
#theme.template_name = obj_type + '_request_email_subject.txt'
#subject = render_to_string(theme.template, request)
subject = "New "+obj_type+" request"
theme.template_name = 'email_default_sender.txt'
- sender = render_to_string(theme.template, request)
+ sender = render_to_string(theme.template, context)
sender = sender.replace('\n', '')
msg = EmailMultiAlternatives(subject, text_content, sender, recipients)
)
b.save()
# sends email to user to activate the email
+ request['current_site'] = get_current_site(request)
+ request['theme'] = theme
theme.template_name = 'activate_user.html'
html_content = render_to_string(theme.template, request)
theme.template_name = 'activate_user.txt'
from django.contrib import messages
from django.contrib.auth.decorators import login_required
from django.core.mail import EmailMultiAlternatives, send_mail
-from django.contrib.sites.models import Site
from manifold.core.query import Query
from manifoldapi.manifoldapi import execute_query, execute_admin_query
from ui.topmenu import topmenu_items_live, the_user
from myslice.theme import ThemeView
-from myslice.settings import logger
-
+from myslice.settings import logger
def ValuesQuerySetToDict(vqs):
return [item for item in vqs]
page = Page(self.request)
#page.add_js_files ( [ "js/jquery.validate.js", "js/my_account.register.js", "js/my_account.edit_profile.js" ] )
#page.add_css_files ( [ "css/onelab.css", "css/account_view.css","css/plugin.css" ] )
-
- # get the domain url
- current_site = Site.objects.get_current()
- current_site = current_site.domain
+ if self.request.is_secure():
+ current_site = 'https://'
+ else:
+ current_site = 'http://'
+ current_site += self.request.META['HTTP_HOST']
for key, value in kwargs.iteritems():
if key == "hash_code":
from django.template.loader import render_to_string
from django.shortcuts import render
from django.contrib.auth import get_user_model
-from django.contrib.sites.models import Site
from unfold.page import Page
from unfold.loginrequired import FreeAccessView
reg_password = request.POST['pi_password']
salt = randint(1,100000)
- # get the domain url
- current_site = Site.objects.get_current()
- current_site = current_site.domain
+
+ if request.is_secure():
+ current_site = 'https://'
+ else:
+ current_site = 'http://'
+ current_site += request.META['HTTP_HOST']
email_hash = md5(str(salt)+reg_email).hexdigest()
user_request = {
template_name = 'projectrequest_view.html'
def getAuthorities(self, request):
- if self.theme == 'fed4fire':
- authorities_query = Query.get('myslice:authority').select('authority_hrn')
- else:
- authorities_query = Query.get('authority').select('name', 'authority_hrn')
+ #if self.theme == 'fed4fire':
+ 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:
# Remove the root authority from the list
matching = [s for s in authorities if "." in s['authority_hrn']]
authorities = sorted(matching, key=lambda k: k['authority_hrn'])
- if self.theme != 'fed4fire':
- authorities = sorted(matching, key=lambda k: k['name'])
+ #if self.theme != 'fed4fire':
+ # authorities = sorted(matching, key=lambda k: k['name'])
return authorities
def getUserAuthority(self, request):
from django.shortcuts import render
from django.contrib.auth import get_user_model
-from django.contrib.sites.models import Site
from unfold.page import Page
from unfold.loginrequired import FreeAccessView
reg_form = {}
# The form has been submitted
- # get the domain url
- current_site = Site.objects.get_current()
- current_site = current_site.domain
-
+ if wsgi_request.is_secure():
+ current_site = 'https://'
+ else:
+ current_site = 'http://'
+ current_site += wsgi_request.META['HTTP_HOST']
+
+
logger.debug("############ BREAKPOINT 3 #################")
post_email = wsgi_request.POST.get('email','').lower()
salt = randint(1,100000)
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
authority_hrn = None
authority_name = None
# Retrieve the list of authorities
- if self.theme == 'fed4fire':
- authorities_query = Query.get('myslice:authority').select('authority_hrn')
- else:
- authorities_query = Query.get('authority').select('name', 'authority_hrn')
+ #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':
- authorities = sorted(authorities, key=lambda k: k['name'])
+ #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')
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 'name' in authority and 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)
if method == 'POST':
# The form has been submitted
- # get the domain url
- current_site = Site.objects.get_current()
- current_site = current_site.domain
-
- if theme.theme != 'fed4fire':
+ 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']
+ # 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')
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:
config['authority'] = config.get('authority')
user_details[0]['parent_authority'] = config['authority']
- ## check user is pi or not
- platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled')
- 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)
- for platform_detail in platform_details:
- for account_detail in account_details:
- if platform_detail['platform_id'] == account_detail['platform_id']:
- if 'config' in account_detail and account_detail['config'] is not '':
- account_config = json.loads(account_detail['config'])
- if 'myslice' in platform_detail['platform']:
- acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
-
- # assigning values
- if acc_auth_cred == {}:
- pi = "is_not_pi"
- else:
- pi = "is_pi"
-
- return render_to_response(self.template, {"slice": slicename, "user_details":user_details[0], "pi":pi, "theme": self.theme, "username": request.user, "section":"users"}, context_instance=RequestContext(request))
+ return render_to_response(self.template, {"slice": slicename, "user_details":user_details[0], "theme": self.theme, "username": request.user, "section":"users"}, context_instance=RequestContext(request))