web/views/editcontroller.py
changeset 10730 874ac29b515d
parent 10669 155c29e0ed1c
child 10932 cb217b2b3463
equal deleted inserted replaced
10729:6ca54ea4ba4d 10730:874ac29b515d
    21 
    21 
    22 from warnings import warn
    22 from warnings import warn
    23 from collections import defaultdict
    23 from collections import defaultdict
    24 
    24 
    25 from datetime import datetime
    25 from datetime import datetime
       
    26 
       
    27 from six import text_type
    26 
    28 
    27 from logilab.common.deprecation import deprecated
    29 from logilab.common.deprecation import deprecated
    28 from logilab.common.graph import ordered_nodes
    30 from logilab.common.graph import ordered_nodes
    29 
    31 
    30 from rql.utils import rqlvar_maker
    32 from rql.utils import rqlvar_maker
   195                 eid = self.edit_entity(formparams)
   197                 eid = self.edit_entity(formparams)
   196         except (RequestError, NothingToEdit) as ex:
   198         except (RequestError, NothingToEdit) as ex:
   197             if '__linkto' in req.form and 'eid' in req.form:
   199             if '__linkto' in req.form and 'eid' in req.form:
   198                 self.execute_linkto()
   200                 self.execute_linkto()
   199             elif not ('__delete' in req.form or '__insert' in req.form):
   201             elif not ('__delete' in req.form or '__insert' in req.form):
   200                 raise ValidationError(None, {None: unicode(ex)})
   202                 raise ValidationError(None, {None: text_type(ex)})
   201         # all pending inlined relations to newly created entities have been
   203         # all pending inlined relations to newly created entities have been
   202         # treated now (pop to ensure there are no attempt to add new ones)
   204         # treated now (pop to ensure there are no attempt to add new ones)
   203         pending_inlined = req.data.pop('pending_inlined')
   205         pending_inlined = req.data.pop('pending_inlined')
   204         assert not pending_inlined, pending_inlined
   206         assert not pending_inlined, pending_inlined
   205         # handle all other remaining relations now
   207         # handle all other remaining relations now
   213             todelete = req.list_form_param('__delete', req.form, pop=True)
   215             todelete = req.list_form_param('__delete', req.form, pop=True)
   214             if todelete:
   216             if todelete:
   215                 autoform.delete_relations(self._cw, todelete)
   217                 autoform.delete_relations(self._cw, todelete)
   216         self._cw.remove_pending_operations()
   218         self._cw.remove_pending_operations()
   217         if self.errors:
   219         if self.errors:
   218             errors = dict((f.name, unicode(ex)) for f, ex in self.errors)
   220             errors = dict((f.name, text_type(ex)) for f, ex in self.errors)
   219             raise ValidationError(valerror_eid(form.get('__maineid')), errors)
   221             raise ValidationError(valerror_eid(form.get('__maineid')), errors)
   220 
   222 
   221     def _insert_entity(self, etype, eid, rqlquery):
   223     def _insert_entity(self, etype, eid, rqlquery):
   222         rql = rqlquery.insert_query(etype)
   224         rql = rqlquery.insert_query(etype)
   223         try:
   225         try:
   263         # if there are some inlined field which were waiting for this entity's
   265         # if there are some inlined field which were waiting for this entity's
   264         # creation, add relevant data to the rqlquery
   266         # creation, add relevant data to the rqlquery
   265         for form_, field in req.data['pending_inlined'].pop(entity.eid, ()):
   267         for form_, field in req.data['pending_inlined'].pop(entity.eid, ()):
   266             rqlquery.set_inlined(field.name, form_.edited_entity.eid)
   268             rqlquery.set_inlined(field.name, form_.edited_entity.eid)
   267         if self.errors:
   269         if self.errors:
   268             errors = dict((f.role_name(), unicode(ex)) for f, ex in self.errors)
   270             errors = dict((f.role_name(), text_type(ex)) for f, ex in self.errors)
   269             raise ValidationError(valerror_eid(entity.eid), errors)
   271             raise ValidationError(valerror_eid(entity.eid), errors)
   270         if eid is None: # creation or copy
   272         if eid is None: # creation or copy
   271             entity.eid = eid = self._insert_entity(etype, formparams['eid'], rqlquery)
   273             entity.eid = eid = self._insert_entity(etype, formparams['eid'], rqlquery)
   272         elif rqlquery.edited: # edition of an existant entity
   274         elif rqlquery.edited: # edition of an existant entity
   273             self.check_concurrent_edition(formparams, eid)
   275             self.check_concurrent_edition(formparams, eid)