Initial slice view with users
authorJordan Augé <jordan.auge@lip6.fr>
Tue, 14 May 2013 23:27:41 +0000 (01:27 +0200)
committerJordan Augé <jordan.auge@lip6.fr>
Tue, 14 May 2013 23:27:41 +0000 (01:27 +0200)
auth/manifoldbackend.py
manifold/core/query.py
trash/sliceview.py
unfold/composite.py

index 73ba446..b1e3c94 100644 (file)
@@ -3,6 +3,7 @@ import time
 from django.contrib.auth.models import User
 
 from manifold.manifoldapi import ManifoldAPI, ManifoldResult
+from manifold.core.query        import Query
 
 # Name my backend 'ManifoldBackend'
 class ManifoldBackend:
@@ -20,34 +21,45 @@ class ManifoldBackend:
 
             auth = {'AuthMethod': 'password', 'Username': username, 'AuthString': password}
             api = ManifoldAPI(auth)
-            # Authenticate user and get session key
-            # the new API would expect Get('local:session') instead
-            session_result = api.GetSession()
-            session = session_result.ok_value()
-            if not session:
-                print "GetSession failed",session_result.error()
-                return
-            
-            print 'DEALING with session',session
-            #self.session = session
-            # Change GetSession() at some point to return expires as well
-            expires = time.time() + (24 * 60 * 60)
+#old            # Authenticate user and get session key
+#old            # the new API would expect Get('local:session') instead
+#old            session_result = api.GetSession()
+#old            session = session_result.ok_value()
+#old            if not session:
+#old                print "GetSession failed",session_result.error()
+#old                return
+#old            print 'DEALING with session',session
+#old            #self.session = session
+#old            # Change GetSession() at some point to return expires as well
+#old            expires = time.time() + (24 * 60 * 60)
+
+            sessions_result = api.forward(Query.create('local:session').to_dict())
+            print "result"
+            sessions = sessions_result.ok_value()
+            print "ok"
+            if not sessions:
+                print "GetSession failed", sessions_result.error()
+            print "first"
+            session = sessions[0]
+            print "SESSION=", session
 
             # Change to session authentication
-            api.auth = {'AuthMethod': 'session', 'session': session}
+            api.auth = {'AuthMethod': 'session', 'session': session['session']}
             self.api = api
 
             # Get account details
             # the new API would expect Get('local:user') instead
-            persons_result = api.GetPersons(auth)
+            persons_result = api.forward(Query.get('local:user').to_dict())
             persons = persons_result.ok_value()
             if not persons:
                 print "GetPersons failed",persons_result.error()
                 return
             person = persons[0]
+            print "PERSON=", person
 
-            request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': expires}
-        except:
+            request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']}
+        except Exception, e:
+            print "E: manifoldbackend", e
             return None
 
         try:
index 5a33114..f2ac9d9 100644 (file)
@@ -181,7 +181,7 @@ class Query(object):
             'timestamp': self.timestamp,
             'filters': self.filters,
             'params': self.params,
-            'fields': self.fields
+            'fields': list(self.fields)
         }
 
     def to_json (self, analyzed_query=None):
index 2bec955..fcbaac7 100644 (file)
@@ -47,7 +47,12 @@ def slice_view (request, slicename=tmp_default_slice):
         if debug:
             print "METADATA", md_fields
         # TODO Get default fields
-        main_query.fields = ['slice_hrn', 'resource.hrn', 'resource.hostname', 'resource.type', 'resource.authority']
+        main_query.fields = [
+                'slice_hrn',
+                'resource.hrn', 'resource.hostname', 'resource.type', 'resource.authority',
+                'user.user_hrn',
+#                'application.measurement_point.counter'
+        ]
 
     aq = AnalyzedQuery(main_query)
     page.enqueue_query(main_query, analyzed_query=aq)
@@ -94,10 +99,6 @@ def slice_view (request, slicename=tmp_default_slice):
     )
     main_plugin.insert(tab_resources)
 
-    jj = aq.to_json()
-    print "="*80
-    print "AQ=", jj
-    print "="*80
     tab_resources.insert(
         Hazelnut ( 
             page        = page,
@@ -132,6 +133,70 @@ def slice_view (request, slicename=tmp_default_slice):
         )
     )
 
+    # XXX Let's hardcode users also for now
+    sq = aq.subquery('user')
+    
+    tab_users = Tabs (
+        page         = page,
+        title        = 'Users',
+        domid        = 'thetabs2',
+        # activeid   = 'checkboxes',
+        active_domid = 'checkboxes2',
+    )
+    main_plugin.insert(tab_users)
+
+    tab_users.insert(
+        Hazelnut ( 
+            page        = page,
+            title       = 'List',
+            domid       = 'checkboxes2',
+            # tab's sons preferably turn this off
+            togglable   = False,
+            # this is the query at the core of the slice list
+            query       = sq,
+            checkboxes  = True,
+            datatables_options = { 
+                # for now we turn off sorting on the checkboxes columns this way
+                # this of course should be automatic in hazelnut
+                'aoColumns'      : [None, None, None, None, {'bSortable': False}],
+                'iDisplayLength' : 25,
+                'bLengthChange'  : True,
+            },
+        )
+    )
+
+    # XXX Let's hardcode measurements also for now
+    sq = aq.subquery('measurement')
+    
+    tab_users = Tabs (
+        page         = page,
+        title        = 'Measurements',
+        domid        = 'thetabs3',
+        # activeid   = 'checkboxes',
+        active_domid = 'checkboxes3',
+    )
+    main_plugin.insert(tab_users)
+
+    tab_users.insert(
+        Hazelnut ( 
+            page        = page,
+            title       = 'List',
+            domid       = 'checkboxes3',
+            # tab's sons preferably turn this off
+            togglable   = False,
+            # this is the query at the core of the slice list
+            query       = sq,
+            checkboxes  = True,
+            datatables_options = { 
+                # for now we turn off sorting on the checkboxes columns this way
+                # this of course should be automatic in hazelnut
+                'aoColumns'      : [None, None, None, None, {'bSortable': False}],
+                'iDisplayLength' : 25,
+                'bLengthChange'  : True,
+            },
+        )
+    )
+
     # END OF JORDAN's CODE
 
 #old#    main_plugin = Stack (
index 9007cdc..16e28f3 100644 (file)
@@ -8,9 +8,9 @@ from unfold.plugin import Plugin
 
 class Composite (Plugin):
 
-    def __init__ (self, sons=[], active_domid=None, *args, **kwds):
+    def __init__ (self, sons=None, active_domid=None, *args, **kwds):
         Plugin.__init__ (self, *args, **kwds)
-        self.sons=sons
+        self.sons= sons if sons else []
         self.active_domid=active_domid
         # make sure this is valid, unset otherwise, so we always have exactly one active
         self.check_active_domid()