Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[myslice.git] / portal / supportview.py
1 # this somehow is not used anymore - should it not be ?
2 from django.core.context_processors import csrf
3 from django.http import HttpResponseRedirect
4 from django.contrib.auth import authenticate, login, logout
5 from django.template import RequestContext
6 from django.shortcuts import render_to_response
7 from django.shortcuts import render
8 import json
9 from unfold.loginrequired import FreeAccessView
10
11 from manifoldapi.manifoldresult import ManifoldResult
12 from manifold.core.query                import Query
13 from manifoldapi.manifoldapi            import execute_query
14 from ui.topmenu import topmenu_items, the_user
15 from myslice.configengine import ConfigEngine
16
17 from myslice.theme import ThemeView
18
19 class SupportView (FreeAccessView, ThemeView):
20     template_name = 'supportview.html'
21         
22     
23
24     def post (self,request):
25         env = {}
26         env['theme'] = self.theme
27         return render_to_response(self.template, env, context_instance=RequestContext(request))
28
29     def get (self, request, state=None):
30         env = {}
31
32         if request.user.is_authenticated(): 
33             env['person'] = self.request.user
34             ## check user is pi or not
35             platform_query  = Query().get('local:platform').select('platform_id','platform','gateway_type','disabled')
36             account_query  = Query().get('local:account').select('user_id','platform_id','auth_type','config')
37             platform_details = execute_query(self.request, platform_query)
38             account_details = execute_query(self.request, account_query)
39             for platform_detail in platform_details:
40                 for account_detail in account_details:
41                     if platform_detail['platform_id'] == account_detail['platform_id']:
42                         if 'config' in account_detail and account_detail['config'] is not '':
43                             account_config = json.loads(account_detail['config'])
44                             if 'myslice' in platform_detail['platform']:
45                                 acc_auth_cred = account_config.get('delegated_authority_credentials','N/A')
46             # assigning values
47             if acc_auth_cred == {} or acc_auth_cred == 'N/A':
48                 pi = "is_not_pi"
49             else:
50                 pi = "is_pi"
51             env['pi'] = pi
52         else: 
53             env['person'] = None
54     
55         env['theme'] = self.theme
56         env['section'] = "Support"
57
58         env['username']=the_user(request)
59
60         if state: env['state'] = state
61         elif not env['username']: env['state'] = None
62         # use one or two columns for the layout - not logged in users will see the login prompt
63
64         return render_to_response(self.template, env, context_instance=RequestContext(request))
65