cubicweb/web/views/ajaxcontroller.py
changeset 12187 3a1f742b84cd
parent 11767 432f87a63057
child 12188 fea018b2e056
equal deleted inserted replaced
12183:af5d0a3c3f1a 12187:3a1f742b84cd
   131                 raise RemoteCallFailed('no %s method' % fname)
   131                 raise RemoteCallFailed('no %s method' % fname)
   132         else:
   132         else:
   133             warn('[3.15] remote function %s found on JSonController, '
   133             warn('[3.15] remote function %s found on JSonController, '
   134                  'use AjaxFunction / @ajaxfunc instead' % fname,
   134                  'use AjaxFunction / @ajaxfunc instead' % fname,
   135                  DeprecationWarning, stacklevel=2)
   135                  DeprecationWarning, stacklevel=2)
       
   136         debug_mode = self._cw.vreg.config.debugmode
   136         # no <arg> attribute means the callback takes no argument
   137         # no <arg> attribute means the callback takes no argument
   137         args = self._cw.form.get('arg', ())
   138         args = self._cw.form.get('arg', ())
   138         if not isinstance(args, (list, tuple)):
   139         if not isinstance(args, (list, tuple)):
   139             args = (args,)
   140             args = (args,)
   140         try:
   141         try:
   141             args = [json.loads(arg) for arg in args]
   142             args = [json.loads(arg) for arg in args]
   142         except ValueError as exc:
   143         except ValueError as exc:
   143             self.exception('error while decoding json arguments for '
   144             if debug_mode:
   144                            'js_%s: %s (err: %s)', fname, args, exc)
   145                 self.exception('error while decoding json arguments for '
       
   146                                'js_%s: %s (err: %s)', fname, args, exc)
   145             raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
   147             raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
   146         try:
   148         try:
   147             result = func(*args)
   149             result = func(*args)
   148         except (RemoteCallFailed, DirectResponse):
   150         except (RemoteCallFailed, DirectResponse):
   149             raise
   151             raise
   150         except Exception as exc:
   152         except Exception as exc:
   151             self.exception('an exception occurred while calling js_%s(%s): %s',
   153             if debug_mode:
   152                            fname, args, exc)
   154                 self.exception(
       
   155                     'an exception occurred while calling js_%s(%s): %s',
       
   156                     fname, args, exc)
   153             raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
   157             raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
   154         if result is None:
   158         if result is None:
   155             return ''
   159             return ''
   156         # get unicode on @htmlize methods, encoded string on @jsonize methods
   160         # get unicode on @htmlize methods, encoded string on @jsonize methods
   157         elif isinstance(result, text_type):
   161         elif isinstance(result, text_type):
   217         if rocheck:
   221         if rocheck:
   218             self._cw.ensure_ro_rql(rql)
   222             self._cw.ensure_ro_rql(rql)
   219         try:
   223         try:
   220             return self._cw.execute(rql, args)
   224             return self._cw.execute(rql, args)
   221         except Exception as ex:
   225         except Exception as ex:
   222             self.exception("error in _exec(rql=%s): %s", rql, ex)
   226             if self._cw.vreg.config.debugmode:
       
   227                 self.exception("error in _exec(rql=%s): %s", rql, ex)
   223             return None
   228             return None
   224         return None
   229         return None
   225 
   230 
   226     def _call_view(self, view, paginate=False, **kwargs):
   231     def _call_view(self, view, paginate=False, **kwargs):
   227         divid = self._cw.form.get('divid')
   232         divid = self._cw.form.get('divid')