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:
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:
'timestamp': self.timestamp,
'filters': self.filters,
'params': self.params,
- 'fields': self.fields
+ 'fields': list(self.fields)
}
def to_json (self, analyzed_query=None):
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)
)
main_plugin.insert(tab_resources)
- jj = aq.to_json()
- print "="*80
- print "AQ=", jj
- print "="*80
tab_resources.insert(
Hazelnut (
page = page,
)
)
+ # 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 (
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()