61 |
61 |
62 """ |
62 """ |
63 |
63 |
64 __docformat__ = "restructuredtext en" |
64 __docformat__ = "restructuredtext en" |
65 |
65 |
|
66 from warnings import warn |
66 from functools import partial |
67 from functools import partial |
67 |
68 |
68 from logilab.common.date import strptime |
69 from logilab.common.date import strptime |
69 from logilab.common.registry import yes |
70 from logilab.common.registry import yes |
70 from logilab.common.deprecation import deprecated |
71 from logilab.common.deprecation import deprecated |
112 self._cw.ajax_request = True |
113 self._cw.ajax_request = True |
113 try: |
114 try: |
114 fname = self._cw.form['fname'] |
115 fname = self._cw.form['fname'] |
115 except KeyError: |
116 except KeyError: |
116 raise RemoteCallFailed('no method specified') |
117 raise RemoteCallFailed('no method specified') |
117 try: |
118 # 1/ check first for old-style (JSonController) ajax func for bw compat |
118 func = self._cw.vreg['ajax-func'].select(fname, self._cw) |
119 try: |
119 except ObjectNotFound: |
120 func = getattr(basecontrollers.JSonController, 'js_%s' % fname).im_func |
120 # function not found in the registry, inspect JSonController for |
121 func = partial(func, self) |
121 # backward compatibility |
122 except AttributeError: |
|
123 # 2/ check for new-style (AjaxController) ajax func |
122 try: |
124 try: |
123 func = getattr(basecontrollers.JSonController, 'js_%s' % fname).im_func |
125 func = self._cw.vreg['ajax-func'].select(fname, self._cw) |
124 func = partial(func, self) |
126 except ObjectNotFound: |
125 except AttributeError: |
|
126 raise RemoteCallFailed('no %s method' % fname) |
127 raise RemoteCallFailed('no %s method' % fname) |
127 else: |
128 else: |
128 self.warning('remote function %s found on JSonController, ' |
129 warn('[3.15] remote function %s found on JSonController, ' |
129 'use AjaxFunction / @ajaxfunc instead', fname) |
130 'use AjaxFunction / @ajaxfunc instead' % fname, |
130 except NoSelectableObject: |
131 DeprecationWarning, stacklevel=2) |
131 raise RemoteCallFailed('method %s not available in this context' |
|
132 % fname) |
|
133 # no <arg> attribute means the callback takes no argument |
132 # no <arg> attribute means the callback takes no argument |
134 args = self._cw.form.get('arg', ()) |
133 args = self._cw.form.get('arg', ()) |
135 if not isinstance(args, (list, tuple)): |
134 if not isinstance(args, (list, tuple)): |
136 args = (args,) |
135 args = (args,) |
137 try: |
136 try: |