X-Git-Url: http://git.onelab.eu/?p=myslice.git;a=blobdiff_plain;f=unfold%2Fpage.py;h=9c2fdd7e5fa9de460c9f46e948725f591841220c;hp=7f071c0bf46bb371e311ff6cf1330d732b0f9f8e;hb=20e712f9703d8b2eaf226fdf8807315edcea6a9a;hpb=4b6ded2a59de0a500ba0f2f50a06eb1ef1788027 diff --git a/unfold/page.py b/unfold/page.py index 7f071c0b..9c2fdd7e 100644 --- a/unfold/page.py +++ b/unfold/page.py @@ -10,7 +10,7 @@ from manifold.metadata import MetaData from unfold.prelude import Prelude -from myslice.config import Config +from myslice.configengine import ConfigEngine # decorator to deflect calls on this Page to its prelude def to_prelude (method): @@ -33,7 +33,8 @@ class Page: # queue of queries with maybe a domid, see enqueue_query self._queue=[] # global prelude object - self.prelude=Prelude(css_files=['css/plugin.css','css/onelab_marko.css',]) + # global requirements should go in base.html + self.prelude=Prelude() # record known plugins hashed on their domid def record_plugin (self, plugin): @@ -48,7 +49,7 @@ class Page: # self._queue = [] # this method adds a query to the page - # the query will be exposed to js when calling expose_queries + # the query will be exposed to js when calling __expose_queries, which is done by prelude_env() # additionally if run_it is set to True, this query will be asynchroneously triggered on page load # in this case (exec=True) the js async callback (see manifold.asynchroneous_success) # offers the option to deliver the result to a specific DOM elt (in this case, set domid) @@ -68,10 +69,15 @@ class Page: # we only do this if run_it is set if run_it: self._queue.append ( (query.query_uuid,domid) ) + def generate_records(self, query, generators, number=10): + self.add_js_files('js/record_generator.js'); + js_chunk = '$(document).ready(function() { new RecordGenerator(%s,%s,%s).run(); });'%(query.to_json(),json.dumps(generators),number); + self.add_js_chunks(js_chunk) + # return the javascript code for exposing queries # all queries are inserted in the global manifold object # in addition, the ones enqueued with 'run_it=True' are triggered - def expose_queries (self): + def __expose_queries (self): # compute variables to expose to the template env = {} # expose the json definition of all queries @@ -106,7 +112,7 @@ class Page: metadata_auth = {'AuthMethod':'anonymous'} metadata=MetaData (metadata_auth) - metadata.fetch() + metadata.fetch(self.request) # store it for next time manifold['metadata']=metadata if debug: print "Page.get_metadata: return new value" @@ -115,11 +121,10 @@ class Page: def expose_js_metadata (self): # expose global MANIFOLD_METADATA as a js variable # xxx this is fetched synchroneously.. - self.add_js_init_chunks("var MANIFOLD_METADATA =" + self.get_metadata().to_json() + ";") + self.add_js_init_chunks("var MANIFOLD_METADATA =" + self.get_metadata().to_json() + ";\n") def expose_js_manifold_config (self): - config=Config() - self.add_js_init_chunks(config.manifold_js_export()) + self.add_js_init_chunks(ConfigEngine().manifold_js_export()) #################### requirements/prelude management # just forward to self.prelude - see decorator above @@ -133,5 +138,9 @@ class Page: def add_js_chunks (self):pass @to_prelude def add_css_chunks (self):pass - @to_prelude - def prelude_env (self):pass + + # prelude_env also does expose_queries + def prelude_env (self): + self.__expose_queries() + from_prelude=self.prelude.prelude_env() + return from_prelude