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
6 from engine.prelude import Prelude
7 from engine.manifoldapi import ManifoldAPI
9 # decorator to deflect calls on this PluginSet to its prelude
10 def to_prelude (method):
11 def actual (self, *args, **kwds):
12 prelude_method=Prelude.__dict__[method.__name__]
13 return prelude_method(self.prelude,*args, **kwds)
18 def __init__ (self, request):
22 self.prelude=Prelude(css_files='css/plugin.css')
23 # no queries yet, needed ?
26 self._metadata_javascript=''
27 self.load_metadata(request)
29 # record known plugins hashed on their domid
30 def record_plugin (self, plugin):
31 self._plugins[plugin.domid]=plugin
33 def get_plugin (self, domid):
34 return self._plugins.get(domid,None)
36 def reset_queue (self):
39 # the js async methods (see manifold_async_success)
40 # offer the option to deliver the result to a specific DOM elt
41 # otherwise it goes through the pubsub using query's uuid
42 def enqueue_query (self, query, domid=None):
43 self._queue.append ( (query,domid,) )
45 # return the javascript that triggers all the queries
46 def exec_queue_asynchroneously (self):
48 js += "var manifold_query_array = new Array();\n"
49 for (query,domid) in self._queue:
51 id="'%s'"%domid if domid else 'undefined'
52 js += "manifold_query_array.push({'query':%(qjson)s, 'id':%(id)s});\n"%locals()
53 js += "onFunctionAvailable('manifold_async_exec', function() {manifold_async_exec(manifold_query_array);}, this, true);"
55 # run only once the document is ready
56 js = "$(document).ready(function(){%(js)s})"%locals()
57 self.add_js_chunks (js)
60 def load_metadata(self, request):
61 manifold_api_session_auth = request.session['manifold']['auth']
62 manifold_api = ManifoldAPI(auth=manifold_api_session_auth)
64 fields = ['table', 'column.column',
65 'column.description','column.header', 'column.title',
66 'column.unit', 'column.info_type',
67 'column.resource_type', 'column.value_type',
68 'column.allowed_values', 'column.platforms.platform',
69 'column.platforms.platform_url']
71 results = manifold_api.Get('metadata:table', [], [], fields)
75 self._metadata[method] = res
77 request.session['metadata'] = self._metadata
78 self._metadata_javascript = "all_headers=" + json.dumps(self._metadata) + ";"
79 self.add_js_chunks(self._metadata_javascript)
82 def metadata_get_fields(self, method):
83 return self._metadata[method]['column'].sort()
86 #################### requirements/prelude management
87 # just forward to self.pluginset - see decorator above
89 def add_js_files (self):pass
91 def add_css_files (self):pass
93 def add_js_chunks (self):pass
95 def add_css_chunks (self):pass
97 def template_env (self):pass