--- a/web/request.py Thu Aug 13 09:23:22 2009 +0200
+++ b/web/request.py Thu Aug 13 09:30:03 2009 +0200
@@ -15,11 +15,12 @@
from urlparse import urlsplit
from itertools import count
+from simplejson import dumps
+
from rql.utils import rqlvar_maker
from logilab.common.decorators import cached
from logilab.common.deprecation import deprecated
-
from logilab.mtconverter import xml_escape
from cubicweb.dbapi import DBAPIRequest
@@ -85,9 +86,16 @@
self.next_tabindex = self.tabindexgen.next
# page id, set by htmlheader template
self.pageid = None
- self.varmaker = rqlvar_maker()
self.datadir_url = self._datadir_url()
+ @property
+ def varmaker(self)
+ varmaker = self.get_page_data('rql_varmaker')
+ if varmaker is None:
+ varmaker = rqlvar_maker()
+ self.set_page_data('rql_varmaker', varmaker)
+ return varmaker
+
def set_connection(self, cnx, user=None):
"""method called by the session handler when the user is authenticated
or an anonymous connection is open
@@ -257,6 +265,24 @@
return breadcrumbs.pop()
return self.base_url()
+ def user_rql_callback(self, args, msg=None):
+ """register a user callback to execute some rql query and return an url
+ to call it ready to be inserted in html
+ """
+ def rqlexec(req, rql, args=None, key=None):
+ req.execute(rql, args, key)
+ return self.user_callback(rqlexec, args, msg)
+
+ def user_callback(self, cb, args, msg=None, nonify=False):
+ """register the given user callback and return an url to call it ready to be
+ inserted in html
+ """
+ self.add_js('cubicweb.ajax.js')
+ cbname = self.register_onetime_callback(cb, *args)
+ msg = dumps(msg or '')
+ return "javascript:userCallbackThenReloadPage('%s', %s)" % (
+ cbname, msg)
+
def register_onetime_callback(self, func, *args):
cbname = 'cb_%s' % (
sha.sha('%s%s%s%s' % (time.time(), func.__name__,