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 unfold.prelude import Prelude
8 from manifold.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 # do not call this uncondionnally as we might not even have logged in
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 # xxx this code should probably not be called unconditionnally at page creation time
68 # because we're not sure a user is logged in so we might have no session...
69 if 'manifold' not in request.session:
70 print "Page.expose_js_metadata: no 'manifold' in session... - skipping"
72 # use cached version if present
73 if 'metadata' in request.session.keys():
74 self._metadata = request.session['metadata']
76 manifold_api_session_auth = request.session['manifold']['auth']
77 manifold_api = ManifoldAPI(auth=manifold_api_session_auth)
79 fields = ['table', 'column.column',
80 'column.description','column.header', 'column.title',
81 'column.unit', 'column.info_type',
82 'column.resource_type', 'column.value_type',
83 'column.allowed_values', 'column.platforms.platform',
84 'column.platforms.platform_url']
86 results = manifold_api.Get('metadata:table', [], [], fields)
90 self._metadata[method] = res
92 request.session['metadata'] = self._metadata
94 javascript = "all_headers=" + json.dumps(self._metadata) + ";"
95 self.add_js_chunks(javascript)
97 def metadata_get_fields(self, method):
98 return self._metadata[method]['column'].sort()
100 def expose_js_manifold_config (self):
101 self.add_js_chunks(Config.manifold_js_export())
103 #################### requirements/prelude management
104 # just forward to self.prelude - see decorator above
106 def add_js_files (self):pass
108 def add_css_files (self):pass
110 def add_js_chunks (self):pass
112 def add_css_chunks (self):pass
114 def prelude_env (self):pass