cubicweb/web/views/ajaxcontroller.py
changeset 12542 85194bd49119
parent 12503 b01dd0ef43aa
child 12567 26744ad37953
equal deleted inserted replaced
12541:bbbccb0b3a66 12542:85194bd49119
    61 
    61 
    62 """
    62 """
    63 
    63 
    64 
    64 
    65 
    65 
    66 from warnings import warn
       
    67 from functools import partial
    66 from functools import partial
    68 
    67 
    69 from six import PY2, text_type
    68 from six import PY2, text_type
    70 from six.moves import http_client
    69 from six.moves import http_client
    71 
    70 
   116         try:
   115         try:
   117             fname = self._cw.form['fname']
   116             fname = self._cw.form['fname']
   118         except KeyError:
   117         except KeyError:
   119             raise RemoteCallFailed('no method specified',
   118             raise RemoteCallFailed('no method specified',
   120                                    status=http_client.BAD_REQUEST)
   119                                    status=http_client.BAD_REQUEST)
   121         # 1/ check first for old-style (JSonController) ajax func for bw compat
   120         try:
   122         try:
   121             func = self._cw.vreg['ajax-func'].select(fname, self._cw)
   123             func = getattr(basecontrollers.JSonController, 'js_%s' % fname)
   122         except ObjectNotFound:
   124             if PY2:
   123             raise RemoteCallFailed('no %s method' % fname,
   125                 func = func.__func__
   124                                    status=http_client.BAD_REQUEST)
   126             func = partial(func, self)
       
   127         except AttributeError:
       
   128             # 2/ check for new-style (AjaxController) ajax func
       
   129             try:
       
   130                 func = self._cw.vreg['ajax-func'].select(fname, self._cw)
       
   131             except ObjectNotFound:
       
   132                 raise RemoteCallFailed('no %s method' % fname,
       
   133                                        status=http_client.BAD_REQUEST)
       
   134         else:
       
   135             warn('[3.15] remote function %s found on JSonController, '
       
   136                  'use AjaxFunction / @ajaxfunc instead' % fname,
       
   137                  DeprecationWarning, stacklevel=2)
       
   138         debug_mode = self._cw.vreg.config.debugmode
   125         debug_mode = self._cw.vreg.config.debugmode
   139         # no <arg> attribute means the callback takes no argument
   126         # no <arg> attribute means the callback takes no argument
   140         args = self._cw.form.get('arg', ())
   127         args = self._cw.form.get('arg', ())
   141         if not isinstance(args, (list, tuple)):
   128         if not isinstance(args, (list, tuple)):
   142             args = (args,)
   129             args = (args,)