web/views/basecontrollers.py
changeset 5658 7b9553a9db65
parent 5627 a7e40cccdc9b
child 5715 2c3e83817a8e
equal deleted inserted replaced
5655:ef903fff826d 5658:7b9553a9db65
   260         status, args, entity = _validate_form(self._cw, self._cw.vreg)
   260         status, args, entity = _validate_form(self._cw, self._cw.vreg)
   261         domid = self._cw.form.get('__domid', 'entityForm').encode(
   261         domid = self._cw.form.get('__domid', 'entityForm').encode(
   262             self._cw.encoding)
   262             self._cw.encoding)
   263         return self.response(domid, status, args, entity)
   263         return self.response(domid, status, args, entity)
   264 
   264 
       
   265 def optional_kwargs(extraargs):
       
   266     if extraargs is None:
       
   267         return {}
       
   268     else: # we receive unicode keys which is not supported by the **syntax
       
   269         return dict((str(key), value)
       
   270                     for key, value in extraargs.items())
   265 
   271 
   266 class JSonController(Controller):
   272 class JSonController(Controller):
   267     __regid__ = 'json'
   273     __regid__ = 'json'
   268 
   274 
   269     def publish(self, rset=None):
   275     def publish(self, rset=None):
   419                                               **extraargs)
   425                                               **extraargs)
   420         #except NoSelectableObject:
   426         #except NoSelectableObject:
   421         #    raise RemoteCallFailed('unselectable')
   427         #    raise RemoteCallFailed('unselectable')
   422         return self._call_view(comp, **extraargs)
   428         return self._call_view(comp, **extraargs)
   423 
   429 
       
   430     @xhtmlize
       
   431     def js_render(self, registry, oid, eid=None, selectargs=None, renderargs=None):
       
   432         if eid is not None:
       
   433             rset = self._cw.eid_rset(eid)
       
   434         elif 'rql' in self._cw.form:
       
   435             rset = self._cw.execute(self._cw.form['rql'])
       
   436         else:
       
   437             rset = None
       
   438         selectargs = optional_kwargs(selectargs)
       
   439         view = self._cw.vreg[registry].select(oid, self._cw, rset=rset, **selectargs)
       
   440         return self._call_view(view, **optional_kwargs(renderargs))
       
   441 
   424     @check_pageid
   442     @check_pageid
   425     @xhtmlize
   443     @xhtmlize
   426     def js_inline_creation_form(self, peid, petype, ttype, rtype, role, i18nctx):
   444     def js_inline_creation_form(self, peid, petype, ttype, rtype, role, i18nctx):
   427         view = self._cw.vreg['views'].select('inline-creation', self._cw,
   445         view = self._cw.vreg['views'].select('inline-creation', self._cw,
   428                                              etype=ttype, rtype=rtype, role=role,
   446                                              etype=ttype, rtype=rtype, role=role,
   438         return _validate_form(self._cw, self._cw.vreg)
   456         return _validate_form(self._cw, self._cw.vreg)
   439 
   457 
   440     @xhtmlize
   458     @xhtmlize
   441     def js_reledit_form(self):
   459     def js_reledit_form(self):
   442         req = self._cw
   460         req = self._cw
   443         args = dict((x, self._cw.form[x])
   461         args = dict((x, req.form[x])
   444                     for x in frozenset(('rtype', 'role', 'reload', 'landing_zone')))
   462                     for x in frozenset(('rtype', 'role', 'reload', 'landing_zone')))
   445         entity = self._cw.entity_from_eid(int(self._cw.form['eid']))
   463         entity = req.entity_from_eid(typed_eid(req.form['eid']))
   446         # note: default is reserved in js land
   464         # note: default is reserved in js land
   447         args['default'] = self._cw.form['default_value']
   465         args['default'] = req.form['default_value']
   448         args['reload'] = json.loads(args['reload'])
   466         args['reload'] = json.loads(args['reload'])
   449         rset = req.eid_rset(int(self._cw.form['eid']))
   467         rset = req.eid_rset(typed_eid(req.form['eid']))
   450         view = req.vreg['views'].select('doreledit', req, rset=rset, rtype=args['rtype'])
   468         view = req.vreg['views'].select('doreledit', req, rset=rset, rtype=args['rtype'])
   451         return self._call_view(view, **args)
   469         return self._call_view(view, **args)
   452 
   470 
   453     @jsonize
   471     @jsonize
   454     def js_i18n(self, msgids):
   472     def js_i18n(self, msgids):