Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[myslice.git] / rest / platform.py
1 from manifold.core.query            import Query, AnalyzedQuery
2
3 from django.views.generic.base      import TemplateView
4
5 from unfold.loginrequired           import LoginRequiredView
6 from django.http                    import HttpResponse
7
8 from manifold.core.query            import Query, AnalyzedQuery
9 from manifoldapi.manifoldapi        import execute_query
10
11 import json
12
13
14 def dispatch(request, platform_name):
15     return get(request, platform_name)
16
17 def get(request, platform_name):
18     
19     platform_query  = Query().get('local:platform').filter_by('disabled', '==', '0').select('platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type')
20     response = execute_query(request,platform_query)
21     
22     q = Query.get('slice').select('slice_hrn')
23     result = execute_query(request,q)
24     print result
25 # #     
26 #     query = Query.get('local:object').select('table')
27 #     results = execute_query(request, query)
28 #     print results
29 #     
30     query = Query.get('local:object').filter_by('table', '==', 'slice').select('column.name')
31     results = execute_query(request, query)
32     print results
33     
34     response_data = {}
35     response_data['columns'] = [ 'platform', 'platform_longname', 'platform_url', 'platform_description','gateway_type' ]
36     response_data['labels'] = [ 'Platform', 'Name', 'Url', 'Description','Gateway Type' ]
37     response_data['data'] = []
38     #response_data['resources'] = { 'total' : len(r) }
39     for r in response :
40         response_data['data'].append([ r['platform'], r['platform_longname'], r['platform_url'], r['platform_description'], r['gateway_type'] ])
41         
42     return HttpResponse(json.dumps(response_data), content_type="application/json")