git://git.onelab.eu
/
myslice.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fixed GUI
[myslice.git]
/
unfold
/
page.py
diff --git
a/unfold/page.py
b/unfold/page.py
index
0d3a81e
..
a9228ec
100644
(file)
--- a/
unfold/page.py
+++ b/
unfold/page.py
@@
-6,11
+6,13
@@
import json
from django.template.loader import render_to_string
from django.template.loader import render_to_string
-from manifold.metadata import MetaData
+from manifold
api
.metadata import MetaData
from unfold.prelude import Prelude
from unfold.prelude import Prelude
-
-from myslice.config import Config
+from unfold.sessioncache import SessionCache
+
+from myslice.configengine import ConfigEngine
+from myslice.settings import logger
# decorator to deflect calls on this Page to its prelude
def to_prelude (method):
# decorator to deflect calls on this Page to its prelude
def to_prelude (method):
@@
-49,7
+51,7
@@
class Page:
# self._queue = []
# this method adds a query to the 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)
# 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)
@@
-69,14
+71,15
@@
class Page:
# we only do this if run_it is set
if run_it: self._queue.append ( (query.query_uuid,domid) )
# 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):
+ def generate_records(self, query, generators, number
=10
):
self.add_js_files('js/record_generator.js');
self.add_js_files('js/record_generator.js');
- self.add_js_chunks('$(document).ready(function() { new RecordGenerator(' + query.to_json() + ', ' + json.dumps(generators) + ', 10).run(); });')
-
+ 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
# 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
# compute variables to expose to the template
env = {}
# expose the json definition of all queries
@@
-105,26
+108,34
@@
class Page:
# if cached, use it
if 'metadata' in manifold and isinstance(manifold['metadata'],MetaData):
# if cached, use it
if 'metadata' in manifold and isinstance(manifold['metadata'],MetaData):
- if debug: print "Page.get_metadata: return cached value"
+
+# cached_metadata = SessionCache().get_metadata(self.request)
+# if cached_metadata and isinstance(cached_metadata, MetaData):
+ logger.debug("Page.get_metadata: return cached value")
return manifold['metadata']
return manifold['metadata']
+# return cached_metadata
metadata_auth = {'AuthMethod':'anonymous'}
metadata_auth = {'AuthMethod':'anonymous'}
- metadata
=
MetaData (metadata_auth)
+ metadata
=
MetaData (metadata_auth)
metadata.fetch(self.request)
# store it for next time
manifold['metadata']=metadata
metadata.fetch(self.request)
# store it for next time
manifold['metadata']=metadata
- if debug: print "Page.get_metadata: return new value"
+# SessionCache().store_metadata(self.request, metadata)
+ logger.debug("Page.get_metadata: return new value")
return metadata
def expose_js_metadata (self):
# expose global MANIFOLD_METADATA as a js variable
# xxx this is fetched synchroneously..
return metadata
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_var(self, name, value):
+ # expose variable as a js value
+ self.add_js_init_chunks("var " + name + "=" + value + ";\n")
def expose_js_manifold_config (self):
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
#################### requirements/prelude management
# just forward to self.prelude - see decorator above
@@
-138,5
+149,9
@@
class Page:
def add_js_chunks (self):pass
@to_prelude
def add_css_chunks (self):pass
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