merge
[unfold.git] / portal / slicetabusers.py
1 from django.template                 import RequestContext
2 from django.shortcuts                import render_to_response
3
4 from manifold.core.query             import Query, AnalyzedQuery
5 from manifoldapi.manifoldapi         import execute_query
6
7 from django.views.generic.base      import TemplateView
8
9 from unfold.loginrequired           import LoginRequiredView
10 from django.http import HttpResponse
11 from django.shortcuts import render
12
13 from unfold.page                     import Page
14 from manifold.core.query             import Query, AnalyzedQuery
15 from manifoldapi.manifoldapi         import execute_query
16
17 from myslice.theme import ThemeView
18 import json
19
20 class SliceUserView (LoginRequiredView, ThemeView):
21     template_name = "slice-tab-users-view.html"
22     
23     def get(self, request, slicename):
24         if request.user.is_authenticated():
25            # user_query  = Query().get('user').select('user_hrn','parent_authority').filter_by('user_hrn','==','$user_hrn')
26             #user_details = execute_query(self.request, user_query)
27             # if sfa returns None
28             #if user_details[0]['parent_authority'] is None:
29                 # find in local DB 
30                 user_query  = Query().get('local:user').select('config')
31                 user_details = execute_query(request, user_query)
32                 for user_config in user_details:
33                         config = json.loads(user_config['config'])
34                         config['authority'] = config.get('authority')
35                         user_details[0]['parent_authority'] = config['authority']
36
37         ## check user is pi or not
38         platform_query  = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled')
39         account_query  = Query().get('local:account').select('user_id','platform_id','auth_type','config')
40         platform_details = execute_query(self.request, platform_query)
41         account_details = execute_query(self.request, account_query)
42         for platform_detail in platform_details:
43             for account_detail in account_details:
44                 if platform_detail['platform_id'] == account_detail['platform_id']:
45                     if 'config' in account_detail and account_detail['config'] is not '':
46                         account_config = json.loads(account_detail['config'])
47                         if 'myslice' in platform_detail['platform']:
48                             acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
49
50         # assigning values
51         if acc_auth_cred == {}:
52             pi = "is_not_pi"
53         else:
54             pi = "is_pi"
55
56         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))