From ef1519837383e5f9bd6918deddb1ebd43514f240 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jordan=20Aug=C3=A9?= Date: Wed, 15 May 2013 01:27:41 +0200 Subject: [PATCH] Initial slice view with users --- auth/manifoldbackend.py | 44 +++++++++++++++--------- manifold/core/query.py | 2 +- trash/sliceview.py | 75 ++++++++++++++++++++++++++++++++++++++--- unfold/composite.py | 4 +-- 4 files changed, 101 insertions(+), 24 deletions(-) diff --git a/auth/manifoldbackend.py b/auth/manifoldbackend.py index 73ba446a..b1e3c943 100644 --- a/auth/manifoldbackend.py +++ b/auth/manifoldbackend.py @@ -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: diff --git a/manifold/core/query.py b/manifold/core/query.py index 5a331148..f2ac9d9d 100644 --- a/manifold/core/query.py +++ b/manifold/core/query.py @@ -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): diff --git a/trash/sliceview.py b/trash/sliceview.py index 2bec9553..fcbaac77 100644 --- a/trash/sliceview.py +++ b/trash/sliceview.py @@ -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 ( diff --git a/unfold/composite.py b/unfold/composite.py index 9007cdc6..16e28f30 100644 --- a/unfold/composite.py +++ b/unfold/composite.py @@ -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() -- 2.43.0