From: Mohamed Larabi Date: Mon, 11 Mar 2013 11:18:33 +0000 (+0100) Subject: load manifold api metadata ... X-Git-Tag: myslice-django-0.1-1~44 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;ds=sidebyside;h=65de85f2c21eb233a46734b95c7f2eee28b35b0f;p=myslice.git load manifold api metadata ... --- diff --git a/engine/pluginset.py b/engine/pluginset.py index 1a0f54ed..0a0e291f 100644 --- a/engine/pluginset.py +++ b/engine/pluginset.py @@ -2,7 +2,9 @@ # keeps a handle on all present plugins for managing their queries in a consistent way # it is expected to exist one such object for a given page +import json from engine.prelude import Prelude +from engine.manifoldapi import ManifoldAPI # decorator to deflect calls on this PluginSet to its prelude def to_prelude (method): @@ -13,12 +15,16 @@ def to_prelude (method): class PluginSet: - def __init__ (self): + def __init__ (self, request): self._plugins = {} # queue of queries self._queue=[] self.prelude=Prelude(css_files='css/plugin.css') # no queries yet, needed ? + # load metadata + self._metadata={} + self._metadata_javascript='' + self.load_metadata(request) # record known plugins hashed on their domid def record_plugin (self, plugin): @@ -50,6 +56,33 @@ class PluginSet: js = "$(document).ready(function(){%(js)s})"%locals() self.add_js_chunks (js) + + def load_metadata(self, request): + manifold_api_session_auth = request.session['manifold']['auth'] + manifold_api = ManifoldAPI(auth=manifold_api_session_auth) + + fields = ['table', 'column.column', + 'column.description','column.header', 'column.title', + 'column.unit', 'column.info_type', + 'column.resource_type', 'column.value_type', + 'column.allowed_values', 'column.platforms.platform', + 'column.platforms.platform_url'] + + results = manifold_api.Get('metadata:table', [], [], fields) + + for res in results: + method = res['table'] + self._metadata[method] = res + + request.session['metadata'] = self._metadata + self._metadata_javascript = "all_headers=" + json.dumps(self._metadata) + ";" + self.add_js_chunks(self._metadata_javascript) + + + def metadata_get_fields(self, method): + return self._metadata[method]['column'].sort() + + #################### requirements/prelude management # just forward to self.pluginset - see decorator above @to_prelude diff --git a/trash/dashboard.py b/trash/dashboard.py index a217ce7c..35eeb336 100644 --- a/trash/dashboard.py +++ b/trash/dashboard.py @@ -19,7 +19,7 @@ from myslice.viewutils import topmenu_items, the_user @login_required def dashboard_view (request): - pluginset = PluginSet() + pluginset = PluginSet(request) slices_query = ManifoldQuery (action='get', method='slice', diff --git a/trash/pluginview.py b/trash/pluginview.py index 626bfada..e0bc2183 100644 --- a/trash/pluginview.py +++ b/trash/pluginview.py @@ -22,7 +22,7 @@ from myslice.viewutils import hard_wired_slice_names, hard_wired_list, lorem_p, @login_required def test_plugin_view (request): - pluginset = PluginSet() + pluginset = PluginSet(request) # variables that will get passed to this template template_env = {}