1 from django.core.context_processors import csrf
2 from django.http import HttpResponseRedirect
3 from django.contrib.auth import authenticate, login, logout
4 from django.template import RequestContext
5 from django.shortcuts import render_to_response
6 from django.shortcuts import render
8 from unfold.loginrequired import LoginRequiredAutoLogoutView
10 from manifold.core.query import Query
11 from manifoldapi.manifoldapi import execute_query
12 from manifoldapi.manifoldresult import ManifoldResult
13 from ui.topmenu import topmenu_items, the_user
14 from myslice.configengine import ConfigEngine
16 from myslice.theme import ThemeView
19 class ServiceDirectoryView (LoginRequiredAutoLogoutView, ThemeView):
20 template_name = 'servicedirectory.html'
21 server_url = "http://157.193.215.125:4001/"
23 # expose this so we can mention the backend URL on the welcome page
24 def default_env (self):
26 'MANIFOLD_URL':ConfigEngine().manifold_url(),
29 def post (self,request):
30 env = self.default_env()
31 env['theme'] = self.theme
32 return render_to_response(self.template, env, context_instance=RequestContext(request))
34 def get (self, request, state=None):
35 env = self.default_env()
37 if request.user.is_authenticated():
38 env['person'] = self.request.user
39 # user_query = Query().get('user').select('user_hrn','parent_authority').filter_by('user_hrn','==','$user_hrn')
40 # user_details = execute_query(self.request, user_query)
42 # env['user_details'] = user_details[0]
44 # env['error'] = "Please check your Credentials"
47 # user_local_query = Query().get('local:user').select('config').filter_by('email','==',str(env['person']))
48 # user_local_details = execute_query(self.request, user_local_query)
49 # user_local = user_local_details[0]
50 # user_local_config = user_local['config']
51 # user_local_config = json.loads(user_local_config)
52 # user_local_authority = user_local_config.get('authority')
53 # if 'user_details' not in env or 'parent_authority' not in env['user_details'] or env['user_details']['parent_authority'] is None:
54 # env['user_details'] = {'parent_authority': user_local_authority}
56 # env['error'] = "Please check your Manifold user config"
57 # ## check user is pi or not
58 # platform_query = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled')
59 # account_query = Query().get('local:account').select('user_id','platform_id','auth_type','config')
60 # platform_details = execute_query(self.request, platform_query)
61 # account_details = execute_query(self.request, account_query)
62 # for platform_detail in platform_details:
63 # for account_detail in account_details:
64 # if platform_detail['platform_id'] == account_detail['platform_id']:
65 # if 'config' in account_detail and account_detail['config'] is not '':
66 # account_config = json.loads(account_detail['config'])
67 # if 'myslice' in platform_detail['platform']:
68 # acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
70 # if acc_auth_cred == {}:
78 env['theme'] = self.theme
79 env['section'] = "Institution"
81 env['username']=the_user(request)
82 env['topmenu_items'] = topmenu_items(None, request)
83 env['servdirurl'] = self.server_url
84 if state: env['state'] = state
85 elif not env['username']: env['state'] = None
86 # use one or two columns for the layout - not logged in users will see the login prompt
87 env['layout_1_or_2']="layout-unfold2.html" if not env['username'] else "layout-unfold1.html"
90 return render_to_response(self.template, env, context_instance=RequestContext(request))