web/request.py
branchtls-sprint
changeset 1801 672acc730ce5
parent 1718 26ff2d292183
child 1977 606923dff11b
--- a/web/request.py	Thu May 14 10:13:59 2009 +0200
+++ b/web/request.py	Thu May 14 10:24:56 2009 +0200
@@ -19,12 +19,14 @@
 from logilab.common.decorators import cached
 from logilab.common.deprecation import obsolete
 
+from logilab.mtconverter import html_escape
+
 from cubicweb.dbapi import DBAPIRequest
 from cubicweb.common.mail import header
 from cubicweb.common.uilib import remove_html_tags
 from cubicweb.utils import SizeConstrainedList, HTMLHead
-from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit, RequestError,
-                          StatusResponse)
+from cubicweb.web import (INTERNAL_FIELD_VALUE, LOGGER, NothingToEdit,
+                          RequestError, StatusResponse)
 
 _MARKER = object()
 
@@ -478,6 +480,23 @@
                 cssfile = self.datadir_url + cssfile
             add_css(cssfile, media)
 
+    def build_ajax_replace_url(self, nodeid, rql, vid, replacemode='replace',
+                               **extraparams):
+        """builds an ajax url that will replace `nodeid`s content
+        :param nodeid: the dom id of the node to replace
+        :param rql: rql to execute
+        :param vid: the view to apply on the resultset
+        :param replacemode: defines how the replacement should be done.
+        Possible values are :
+         - 'replace' to replace the node's content with the generated HTML
+         - 'swap' to replace the node itself with the generated HTML
+         - 'append' to append the generated HTML to the node's content
+        """
+        url = self.build_url('view', rql=rql, vid=vid, __notemplate=1,
+                             **extraparams)
+        return "javascript: loadxhtml('%s', '%s', '%s')" % (
+            nodeid, html_escape(url), replacemode)
+
     # urls/path management ####################################################
 
     def url(self, includeparams=True):