From 4e348dd653e2f7124550f153a30744293eab3b2f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jordan=20Aug=C3=A9?= Date: Mon, 29 Jul 2013 05:42:37 +0200 Subject: [PATCH] updates for onelab portal demo --- auth/manifoldbackend.py | 5 ++++- manifold/core/result_value.py | 5 +++-- manifold/manifoldapi.py | 4 ++++ manifold/manifoldproxy.py | 4 +++- myslice/viewutils.py | 8 ++++++-- plugins/googlemap/googlemap.js | 4 ++++ plugins/tabs/tabs.py | 7 ++++++- portal/views.py | 4 ++-- trash/sliceview.py | 4 ++-- 9 files changed, 34 insertions(+), 11 deletions(-) diff --git a/auth/manifoldbackend.py b/auth/manifoldbackend.py index c58c09eb..f763291a 100644 --- a/auth/manifoldbackend.py +++ b/auth/manifoldbackend.py @@ -39,7 +39,8 @@ class ManifoldBackend: print "ok" if not sessions: print "GetSession failed", sessions_result.error() - print "first" + return + print "first", sessions session = sessions[0] print "SESSION=", session @@ -60,6 +61,8 @@ class ManifoldBackend: request.session['manifold'] = {'auth': api.auth, 'person': person, 'expires': session['expires']} except Exception, e: print "E: manifoldbackend", e + import traceback + traceback.print_exc() return None try: diff --git a/manifold/core/result_value.py b/manifold/core/result_value.py index 7728e8a9..4fe505f8 100644 --- a/manifold/core/result_value.py +++ b/manifold/core/result_value.py @@ -48,10 +48,8 @@ class ResultValue(dict): def __init__(self, **kwargs): - print "KWARGS=", kwargs # Checks given = set(kwargs.keys()) - print "given=", given cstr_success = set(['code', 'origin', 'value']) <= given cstr_error = set(['code', 'type', 'origin', 'description']) <= given assert given <= self.ALLOWED_FIELDS, "Wrong fields in ResultValue constructor: %r" % (given - self.ALLOWED_FIELDS) @@ -95,6 +93,9 @@ class ResultValue(dict): def ok_value(self): return self['value'] + def error(self): + err = "%r" % self['description'] + @staticmethod def to_html (raw_dict): return pprint.pformat (raw_dict).replace("\\n","
") diff --git a/manifold/manifoldapi.py b/manifold/manifoldapi.py index eaf92668..9361b6eb 100644 --- a/manifold/manifoldapi.py +++ b/manifold/manifoldapi.py @@ -52,6 +52,10 @@ class ManifoldAPI: return ResultValue(**result) except Exception,error: + # XXX Connection refused for example + print "** API ERROR **" + import traceback + traceback.print_exc() if debug: print "KO (unexpected exception)",error raise ManifoldException ( ManifoldResult (code=ManifoldCode.UNKNOWN_ERROR, output="%s"%error) ) diff --git a/manifold/manifoldproxy.py b/manifold/manifoldproxy.py index 9d322ca7..f6ceb0ef 100644 --- a/manifold/manifoldproxy.py +++ b/manifold/manifoldproxy.py @@ -90,7 +90,8 @@ with the query passed using POST""" result = manifold_api.forward(manifold_query.to_dict()) # XXX TEMP HACK - result [ 'description' ] = [ ResultValue.to_html (x) for x in result['description'] ] + if 'description' in result and result['description'] and isinstance(result['description'], (tuple, list, set, frozenset)): + result [ 'description' ] = [ ResultValue.to_html (x) for x in result['description'] ] json_answer=json.dumps(result) # if in debug mode we save this so we can use offline mode later @@ -107,6 +108,7 @@ with the query passed using POST""" return HttpResponse (json_answer, mimetype="application/json") except: + print "** PROXY ERROR **" import traceback traceback.print_exc() diff --git a/myslice/viewutils.py b/myslice/viewutils.py index 937fa9bd..a5f89f58 100644 --- a/myslice/viewutils.py +++ b/myslice/viewutils.py @@ -15,10 +15,14 @@ standard_topmenu_items = [ def topmenu_items (current,request=None): result=deepcopy(standard_topmenu_items) + has_user=request.user.is_authenticated() + if has_user: + result.append({ 'label':'Request a slice', 'href': '/portal/slice/request/'}) for d in result: - if d['label'].lower().find(current)>=0: d['is_active']=True + #if d['label'].lower()find(current)>=0: d['is_active']=True + if d['label'] == current: d['is_active']=True + print "CURRENT=", current if not request: return result - has_user=request.user.is_authenticated() # result.append (login_out_items [ has_user] ) return result diff --git a/plugins/googlemap/googlemap.js b/plugins/googlemap/googlemap.js index 62e1d6fb..2b0b88ac 100644 --- a/plugins/googlemap/googlemap.js +++ b/plugins/googlemap/googlemap.js @@ -49,6 +49,10 @@ GoogleMap : GoogleMap }); + /* Events */ + $this.on('show.GoogleMaps', methods.show); + + /* Subscribe to query updates */ jQuery.subscribe('/results/' + options.query_uuid + '/changed', {instance: $this}, update_map); jQuery.subscribe('/update-set/' + options.query_uuid, {instance: $this}, on_resource_changed); diff --git a/plugins/tabs/tabs.py b/plugins/tabs/tabs.py index 0350c264..6da94da1 100644 --- a/plugins/tabs/tabs.py +++ b/plugins/tabs/tabs.py @@ -3,7 +3,7 @@ from unfold.composite import Composite class Tabs (Composite): def requirements (self): - return { 'js_files' : 'js/bootstrap.js', + return { 'js_files' : ['js/tabs.js', 'js/bootstrap.js'], 'css_files' : ['css/bootstrap.css', 'css/tabs.css', ] } @@ -12,3 +12,8 @@ class Tabs (Composite): # see Composite.py for the details of template_env, that exposes global # 'sons' as a list of sons with each a set of a few attributes + def json_settings_list (self): + return [] + + def export_json_settings(self): + return True diff --git a/portal/views.py b/portal/views.py index dd631825..f27b178c 100644 --- a/portal/views.py +++ b/portal/views.py @@ -46,7 +46,7 @@ class DashboardView(TemplateView): # Slow... #slice_query = Query().get('slice').filter_by('user.user_hrn', 'contains', user_hrn).select('slice_hrn') - slice_query = Query().get('user').filter_by('user_hrn', '==', user_hrn).select('slice.slice_hrn') + slice_query = Query().get('user').filter_by('user_hrn', '==', user_hrn).select('user_hrn', 'slice.slice_hrn') auth_query = Query().get('network').select('network_hrn') page.enqueue_query(slice_query) page.enqueue_query(auth_query) @@ -76,7 +76,7 @@ class DashboardView(TemplateView): # more general variables expected in the template context['title'] = 'Test view that combines various plugins' # the menu items on the top - context['topmenu_items'] = topmenu_items('dashboard', self.request) + context['topmenu_items'] = topmenu_items('Dashboard', self.request) # so we can sho who is logged context['username'] = the_user(self.request) diff --git a/trash/sliceview.py b/trash/sliceview.py index 252291f7..b1714876 100644 --- a/trash/sliceview.py +++ b/trash/sliceview.py @@ -66,7 +66,7 @@ def _slice_view (request, slicename): main_query.select( 'slice_hrn', 'resource.resource_hrn', 'resource.hostname', 'resource.type', 'resource.authority', - 'lease.urn', + #'lease.urn', 'user.user_hrn', # 'application.measurement_point.counter' ) @@ -371,7 +371,7 @@ def _slice_view (request, slicename): # more general variables expected in the template template_env [ 'title' ] = 'Test view that combines various plugins' # the menu items on the top - template_env [ 'topmenu_items' ] = topmenu_items('slice', request) + template_env [ 'topmenu_items' ] = topmenu_items('Slice', request) # so we can sho who is logged template_env [ 'username' ] = the_user (request) -- 2.43.0