avoid monkeypatching JsonController in cw, to avoid _potential_ load order problems stable
authorAurelien Campeas <aurelien.campeas@logilab.fr>
Mon, 18 May 2009 14:32:34 +0200
branchstable
changeset 1844 ec51bf1b8be3
parent 1842 c7a22540d6f7
child 1845 bd6a434382b8
avoid monkeypatching JsonController in cw, to avoid _potential_ load order problems
web/views/basecontrollers.py
web/views/treeview.py
--- a/web/views/basecontrollers.py	Mon May 18 14:22:26 2009 +0200
+++ b/web/views/basecontrollers.py	Mon May 18 14:32:34 2009 +0200
@@ -487,6 +487,24 @@
         rql = 'DELETE B bookmarked_by U WHERE B eid %(b)s, U eid %(u)s'
         self.req.execute(rql, {'b': typed_eid(beid), 'u' : self.req.user.eid})
 
+    def js_node_clicked(self, treeid, nodeeid):
+        """add/remove eid in treestate cookie"""
+        from cubicweb.web.views.treeview import treecookiename
+        cookies = self.req.get_cookie()
+        statename = treecookiename(treeid)
+        treestate = cookies.get(statename)
+        if treestate is None:
+            cookies[statename] = nodeeid
+            self.req.set_cookie(cookies, statename)
+        else:
+            marked = set(filter(None, treestate.value.split(';')))
+            if nodeeid in marked:
+                marked.remove(nodeeid)
+            else:
+                marked.add(nodeeid)
+            cookies[statename] = ';'.join(marked)
+            self.req.set_cookie(cookies, statename)
+
     def js_set_cookie(self, cookiename, cookievalue):
         # XXX we should consider jQuery.Cookie
         cookiename, cookievalue = str(cookiename), str(cookievalue)
--- a/web/views/treeview.py	Mon May 18 14:22:26 2009 +0200
+++ b/web/views/treeview.py	Mon May 18 14:32:34 2009 +0200
@@ -13,7 +13,6 @@
 from cubicweb.interfaces import ITree
 from cubicweb.selectors import implements
 from cubicweb.view import EntityView
-from cubicweb.web.views.basecontrollers import jsonize, JSonController
 
 def treecookiename(treeid):
     return str('treestate-%s' % treeid)
@@ -149,21 +148,3 @@
             self.wview(parentvid, self.req.execute(rql), treeid=treeid, initial_load=False)
         w(u'</li>')
 
-@monkeypatch(JSonController)
-@jsonize
-def js_node_clicked(self, treeid, nodeeid):
-    """add/remove eid in treestate cookie"""
-    cookies = self.req.get_cookie()
-    statename = treecookiename(treeid)
-    treestate = cookies.get(statename)
-    if treestate is None:
-        cookies[statename] = nodeeid
-        self.req.set_cookie(cookies, statename)
-    else:
-        marked = set(filter(None, treestate.value.split(';')))
-        if nodeeid in marked:
-            marked.remove(nodeeid)
-        else:
-            marked.add(nodeeid)
-        cookies[statename] = ';'.join(marked)
-        self.req.set_cookie(cookies, statename)