1 # the supervisor for Plugins
2 # keeps a handle on all present plugins for managing their queries in a consistent way
3 # it is expected to exist one such object for a given page
7 from engine.prelude import Prelude
8 from engine.manifoldapi import ManifoldAPI
9 from myslice.config import Config
11 # decorator to deflect calls on this Page to its prelude
12 def to_prelude (method):
13 def actual (self, *args, **kwds):
14 prelude_method=Prelude.__dict__[method.__name__]
15 return prelude_method(self.prelude,*args, **kwds)
20 def __init__ (self, request):
22 # all plugins mentioned in this page
26 # global prelude object
27 self.prelude=Prelude(css_files='css/plugin.css')
30 self._metadata_javascript=''
31 self.expose_js_metadata()
33 # record known plugins hashed on their domid
34 def record_plugin (self, plugin):
35 self._plugins[plugin.domid]=plugin
37 def get_plugin (self, domid):
38 return self._plugins.get(domid,None)
40 def reset_queue (self):
43 # the js async methods (see manifold_async_success)
44 # offer the option to deliver the result to a specific DOM elt
45 # otherwise (i.e. if domid not provided)
46 # it goes through the pubsub using query's uuid
47 def enqueue_query (self, query, domid=None):
48 self._queue.append ( (query,domid,) )
50 # return the javascript that triggers all the queries
51 def exec_queue_asynchroneously (self):
53 js += "var async_queries = new Array();\n"
54 for (query,domid) in self._queue:
56 id="'%s'"%domid if domid else 'undefined'
57 js += "async_queries.push({'query':%(qjson)s, 'id':%(id)s});\n"%locals()
58 js += "onFunctionAvailable('manifold_async_exec', function() {manifold_async_exec(async_queries);}, this, true);"
60 # run only once the document is ready
61 js = "$(document).ready(function(){%(js)s})"%locals()
62 self.add_js_chunks (js)
65 def expose_js_metadata(self):
67 if 'metadata' not in request.session.keys():
68 manifold_api_session_auth = request.session['manifold']['auth']
69 manifold_api = ManifoldAPI(auth=manifold_api_session_auth)
71 fields = ['table', 'column.column',
72 'column.description','column.header', 'column.title',
73 'column.unit', 'column.info_type',
74 'column.resource_type', 'column.value_type',
75 'column.allowed_values', 'column.platforms.platform',
76 'column.platforms.platform_url']
78 results = manifold_api.Get('metadata:table', [], [], fields)
82 self._metadata[method] = res
84 request.session['metadata'] = self._metadata
85 self._metadata_javascript = "all_headers=" + json.dumps(self._metadata) + ";"
86 self.add_js_chunks(self._metadata_javascript)
88 self._metadata = request.session['metadata']
90 self._metadata_javascript = "all_headers=" + json.dumps(self._metadata) + ";"
91 self.add_js_chunks(self._metadata_javascript)
93 def metadata_get_fields(self, method):
94 return self._metadata[method]['column'].sort()
96 def expose_js_manifold_config (self):
97 self.add_js_chunks(Config.manifold_js_export())
99 #################### requirements/prelude management
100 # just forward to self.prelude - see decorator above
102 def add_js_files (self):pass
104 def add_css_files (self):pass
106 def add_js_chunks (self):pass
108 def add_css_chunks (self):pass
110 def template_env (self):pass