web/views/editcontroller.py
changeset 7584 e1881933f366
parent 7182 09454384fff8
child 7942 d12c21ea4cd4
equal deleted inserted replaced
7583:6632c762cd63 7584:e1881933f366
     1 # copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2011 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
    20 __docformat__ = "restructuredtext en"
    20 __docformat__ = "restructuredtext en"
    21 
    21 
    22 from warnings import warn
    22 from warnings import warn
    23 
    23 
    24 from rql.utils import rqlvar_maker
    24 from rql.utils import rqlvar_maker
    25 
       
    26 from logilab.common.textutils import splitstrip
       
    27 
    25 
    28 from cubicweb import Binary, ValidationError, typed_eid
    26 from cubicweb import Binary, ValidationError, typed_eid
    29 from cubicweb.view import EntityAdapter, implements_adapter_compat
    27 from cubicweb.view import EntityAdapter, implements_adapter_compat
    30 from cubicweb.selectors import is_instance
    28 from cubicweb.selectors import is_instance
    31 from cubicweb.web import (INTERNAL_FIELD_VALUE, RequestError, NothingToEdit,
    29 from cubicweb.web import (INTERNAL_FIELD_VALUE, RequestError, NothingToEdit,
   188             # XXX inlined forms formid should be saved in a different formparams entry
   186             # XXX inlined forms formid should be saved in a different formparams entry
   189             # inbetween, use cubicweb standard formid for inlined forms
   187             # inbetween, use cubicweb standard formid for inlined forms
   190             formid = 'edition'
   188             formid = 'edition'
   191         form = self._cw.vreg['forms'].select(formid, self._cw, entity=entity)
   189         form = self._cw.vreg['forms'].select(formid, self._cw, entity=entity)
   192         eid = form.actual_eid(entity.eid)
   190         eid = form.actual_eid(entity.eid)
       
   191         try:
       
   192             editedfields = formparams['_cw_entity_fields']
       
   193         except KeyError:
       
   194             try:
       
   195                 editedfields = formparams['_cw_edited_fields']
       
   196                 warn('[3.13] _cw_edited_fields has been renamed _cw_entity_fields',
       
   197                      DeprecationWarning)
       
   198             except KeyError:
       
   199                 raise RequestError(self._cw._('no edited fields specified for entity %s' % entity.eid))
   193         form.formvalues = {} # init fields value cache
   200         form.formvalues = {} # init fields value cache
   194         try:
   201         for field in form.iter_modified_fields(editedfields, entity):
   195             editedfields = formparams['_cw_edited_fields']
   202             self.handle_formfield(form, field, rqlquery)
   196         except KeyError:
       
   197             raise RequestError(self._cw._('no edited fields specified for entity %s' % entity.eid))
       
   198         for editedfield in splitstrip(editedfields):
       
   199             try:
       
   200                 name, role = editedfield.split('-')
       
   201             except:
       
   202                 name = editedfield
       
   203                 role = None
       
   204             if form.field_by_name.im_func.func_code.co_argcount == 4: # XXX
       
   205                 field = form.field_by_name(name, role, eschema=entity.e_schema)
       
   206             else:
       
   207                 field = form.field_by_name(name, role)
       
   208             if field.has_been_modified(form):
       
   209                 self.handle_formfield(form, field, rqlquery)
       
   210         if self.errors:
   203         if self.errors:
   211             errors = dict((f.role_name(), unicode(ex)) for f, ex in self.errors)
   204             errors = dict((f.role_name(), unicode(ex)) for f, ex in self.errors)
   212             raise ValidationError(valerror_eid(entity.eid), errors)
   205             raise ValidationError(valerror_eid(entity.eid), errors)
   213         if eid is None: # creation or copy
   206         if eid is None: # creation or copy
   214             entity.eid = self._insert_entity(etype, formparams['eid'], rqlquery)
   207             entity.eid = self._insert_entity(etype, formparams['eid'], rqlquery)