cw3.2 update: JSonController methods must be decorated with either jsonize or xhtmlize
authorAdrien Di Mascio <Adrien.DiMascio@logilab.fr>
Mon, 18 May 2009 08:33:12 +0200
changeset 27 590da2e84eab
parent 26 38795a236973
child 31 7e44b20cfdcd
cw3.2 update: JSonController methods must be decorated with either jsonize or xhtmlize
views.py
--- a/views.py	Mon May 18 08:29:36 2009 +0200
+++ b/views.py	Mon May 18 08:33:12 2009 +0200
@@ -8,13 +8,14 @@
 
 import simplejson
 
+from logilab.common.decorators import monkeypatch
 from logilab.mtconverter import html_escape
 
 from cubicweb.selectors import implements, rql_condition
 from cubicweb.view import EntityView
 from cubicweb.common.mixins import TreePathMixIn
 from cubicweb.web import stdmsgs, uicfg, component
-from cubicweb.web.views import baseviews
+from cubicweb.web.views import baseviews, basecontrollers
 
 # displayed by the above component
 uicfg.primaryview_section.tag_object_of(('*', 'applied_to', '*'), 'hidden')
@@ -122,16 +123,16 @@
 
 # add some classification schema related methods to the Jsoncontroller ########
 
-from cubicweb.web.views.basecontrollers import JSonController
-
+@monkeypatch(basecontrollers.JSonController)
+@basecontrollers.jsonize
 def js_possible_keywords(self, eid):
     rql = ('DISTINCT Any N WHERE K is Keyword, K name N, NOT K applied_to X, '
            'X eid %(x)s, K included_in C, C classifies ET, X is ET')
     rset = self.cursor.execute(rql, {'x' : eid, 'u' : self.req.user.eid}, 'x')
     return [name for (name,) in rset]
-JSonController.js_possible_keywords = js_possible_keywords
 
-
+@monkeypatch(basecontrollers.JSonController)
+@basecontrollers.jsonize
 def js_add_keywords(self, eid, kwlist):
     msg = self.req._('keywords applied')
     try:
@@ -159,5 +160,3 @@
         self.exception(unicode(ex))
         return self.req._('A problem occured while applying keywords')
     return msg
-
-JSonController.js_add_keywords = js_add_keywords