manage institution: hide slices, show only in projects
[myslice.git] / portal / managementtababout.py
1 import json
2 # this somehow is not used anymore - should it not be ?
3 from django.core.context_processors import csrf
4 from django.http import HttpResponseRedirect
5 from django.contrib.auth import authenticate, login, logout
6 from django.template import RequestContext
7 from django.shortcuts import render_to_response
8 from django.shortcuts import render
9
10 from unfold.loginrequired import FreeAccessView
11
12 from manifold.core.query            import Query
13 from manifoldapi.manifoldapi        import execute_query
14 from manifoldapi.manifoldresult import ManifoldResult
15
16 from myslice.configengine import ConfigEngine
17 from myslice.theme import ThemeView
18 from myslice.settings import logger
19
20 class ManagementAboutView (FreeAccessView, ThemeView):
21     template_name = 'management-tab-about.html'
22
23     def get (self, request):
24         
25         authority_contacts = {}
26         authority = {'authority_hrn':'fed4fire.upmc'}
27         if request.user.is_authenticated(): 
28             user_local_query  = Query().get('local:user').select('config').filter_by('email','==',str(self.request.user))
29             user_local_details = execute_query(self.request, user_local_query)
30             user_authority = json.loads(user_local_details[0]['config']).get('authority')
31             logger.info("**************________    management about  = {}".format(user_authority))
32             # XXX Should be done using Metadata
33             # select column.name from local:object where table=='authority'
34             authority_query = Query().get('authority').select('authority_hrn', 'name', 'address', 'enabled','description', 
35                                                               'scientific', 'city', 'name', 'url', 'country', 'enabled', 'longitude', 
36                                                               'tech', 'latitude', 'pi_users', 'onelab_membership', 
37                                                               'postcode').filter_by('authority_hrn','==',user_authority)
38             authority_details = execute_query(self.request, authority_query)
39             
40             if authority_details :
41                 authority = authority_details[0]
42                 if 'scientific' in authority and authority['scientific'] is not None:
43                     authority_contacts['scientific'] = [ x.strip()[1:-1] for x in authority['scientific'][1:-1].split(',') ]
44                 if 'technical' in authority and authority['technical'] is not None:
45                     authority_contacts['technical'] = [ x.strip()[1:-1] for x in authority['tech'][1:-1].split(',') ]
46                 if 'legal' in authority and authority['legal'] is not None:
47                     authority_contacts['legal'] = [ x.strip().replace('"','') for x in authority['legal'][1:-1].split(',') ]
48             else :
49                 authority_contacts = None
50                 authority = None
51             
52         return render_to_response(self.template, { 'theme' : self.theme, 'authority' : authority, 'authority_contacts' : authority_contacts }, context_instance=RequestContext(request))
53