Example #1
0
 def test_encoding_entity_in_list(self):
     e = Entity(None)
     e.cw_attr_cache['pouet'] = 'hop'
     e.eid = 2
     self.assertEqual(json.loads(self.encode([e])), [{
         'pouet': 'hop',
         'eid': 2
     }])
Example #2
0
 def test_encoding_bare_entity(self):
     e = Entity(None)
     e.cw_attr_cache['pouet'] = 'hop'
     e.eid = 2
     self.assertEqual(json.loads(self.encode(e)), {
         'pouet': 'hop',
         'eid': 2
     })
Example #3
0
 def _init_params(self, subvid, treeid, initial_load, morekwargs):
     form = self._cw.form
     if subvid is None:
         subvid = form.pop('treesubvid', self.subvid)  # consume it
     if treeid is None:
         treeid = form.pop('treeid', None)
         if treeid is None:
             treeid = 'throw_away' + make_uid('uid')
     if 'morekwargs' in self._cw.form:
         ajaxargs = json.loads(form.pop('morekwargs'))
         # got unicode & python keywords must be strings
         morekwargs.update(dict((str(k), v)
                                for k, v in ajaxargs.items()))
     return subvid, treeid
Example #4
0
def reledit_form(self):
    req = self._cw
    args = dict((x, req.form[x])
                for x in ('formid', 'rtype', 'role', 'reload', 'action'))
    rset = req.eid_rset(int(self._cw.form['eid']))
    try:
        args['reload'] = json.loads(args['reload'])
    except ValueError:  # not true/false, an absolute url
        assert args['reload'].startswith('http')
    view = req.vreg['views'].select('reledit',
                                    req,
                                    rset=rset,
                                    rtype=args['rtype'])
    return self._call_view(view, **args)
Example #5
0
 def publish(self, rset=None):
     self._cw.ajax_request = True
     try:
         fname = self._cw.form['fname']
     except KeyError:
         raise RemoteCallFailed('no method specified',
                                status=http_client.BAD_REQUEST)
     try:
         func = self._cw.vreg['ajax-func'].select(fname, self._cw)
     except ObjectNotFound:
         raise RemoteCallFailed('no %s method' % fname,
                                status=http_client.BAD_REQUEST)
     debug_mode = self._cw.vreg.config.debugmode
     # no <arg> attribute means the callback takes no argument
     args = self._cw.form.get('arg', ())
     if not isinstance(args, (list, tuple)):
         args = (args, )
     try:
         args = [json.loads(arg) for arg in args]
     except ValueError as exc:
         if debug_mode:
             self.exception(
                 'error while decoding json arguments for '
                 'js_%s: %s (err: %s)', fname, args, exc)
         raise RemoteCallFailed(exc_message(exc, self._cw.encoding),
                                status=http_client.BAD_REQUEST)
     try:
         result = func(*args)
     except (RemoteCallFailed, DirectResponse):
         raise
     except ValidationError as exc:
         raise RemoteCallFailed(exc_message(exc, self._cw.encoding),
                                status=http_client.BAD_REQUEST)
     except Exception as exc:
         if debug_mode:
             self.exception(
                 'an exception occurred while calling js_%s(%s): %s', fname,
                 args, exc)
         raise RemoteCallFailed(exc_message(exc, self._cw.encoding))
     if result is None:
         return b''
     # get unicode on @htmlize methods, encoded string on @jsonize methods
     elif isinstance(result, str):
         return result.encode(self._cw.encoding)
     return result
Example #6
0
 def parse_string(self, data):
     return json.loads(data.decode('ascii'))
Example #7
0
def loadjson(value):
    return json.loads(html_unescape(value))