19 |
19 |
20 from warnings import warn |
20 from warnings import warn |
21 from collections import defaultdict |
21 from collections import defaultdict |
22 |
22 |
23 from datetime import datetime |
23 from datetime import datetime |
24 |
|
25 from six import text_type |
|
26 |
24 |
27 from logilab.common.graph import ordered_nodes |
25 from logilab.common.graph import ordered_nodes |
28 |
26 |
29 from rql.utils import rqlvar_maker |
27 from rql.utils import rqlvar_maker |
30 |
28 |
199 self.edit_entity(formparams) |
197 self.edit_entity(formparams) |
200 except (RequestError, NothingToEdit) as ex: |
198 except (RequestError, NothingToEdit) as ex: |
201 if '__linkto' in req.form and 'eid' in req.form: |
199 if '__linkto' in req.form and 'eid' in req.form: |
202 self.execute_linkto() |
200 self.execute_linkto() |
203 elif '__delete' not in req.form: |
201 elif '__delete' not in req.form: |
204 raise ValidationError(None, {None: text_type(ex)}) |
202 raise ValidationError(None, {None: str(ex)}) |
205 # all pending inlined relations to newly created entities have been |
203 # all pending inlined relations to newly created entities have been |
206 # 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) |
207 pending_inlined = req.data.pop('pending_inlined') |
205 pending_inlined = req.data.pop('pending_inlined') |
208 assert not pending_inlined, pending_inlined |
206 assert not pending_inlined, pending_inlined |
209 pending_values = req.data.pop('pending_values') |
207 pending_values = req.data.pop('pending_values') |
232 todelete = req.list_form_param('__delete', req.form, pop=True) |
230 todelete = req.list_form_param('__delete', req.form, pop=True) |
233 if todelete: |
231 if todelete: |
234 autoform.delete_relations(self._cw, todelete) |
232 autoform.delete_relations(self._cw, todelete) |
235 self._cw.remove_pending_operations() |
233 self._cw.remove_pending_operations() |
236 if self.errors: |
234 if self.errors: |
237 errors = dict((f.name, text_type(ex)) for f, ex in self.errors) |
235 errors = dict((f.name, str(ex)) for f, ex in self.errors) |
238 raise ValidationError(valerror_eid(form.get('__maineid')), errors) |
236 raise ValidationError(valerror_eid(form.get('__maineid')), errors) |
239 |
237 |
240 def _insert_entity(self, etype, eid, rqlquery): |
238 def _insert_entity(self, etype, eid, rqlquery): |
241 rql = rqlquery.insert_query(etype) |
239 rql = rqlquery.insert_query(etype) |
242 try: |
240 try: |
283 # creation, add relevant data to the rqlquery |
281 # creation, add relevant data to the rqlquery |
284 for form_, field in req.data['pending_inlined'].pop(entity.eid, ()): |
282 for form_, field in req.data['pending_inlined'].pop(entity.eid, ()): |
285 rqlquery.set_inlined(field.name, form_.edited_entity.eid) |
283 rqlquery.set_inlined(field.name, form_.edited_entity.eid) |
286 if not rqlquery.canceled: |
284 if not rqlquery.canceled: |
287 if self.errors: |
285 if self.errors: |
288 errors = dict((f.role_name(), text_type(ex)) for f, ex in self.errors) |
286 errors = dict((f.role_name(), str(ex)) for f, ex in self.errors) |
289 raise ValidationError(valerror_eid(entity.eid), errors) |
287 raise ValidationError(valerror_eid(entity.eid), errors) |
290 if eid is None: # creation or copy |
288 if eid is None: # creation or copy |
291 entity.eid = eid = self._insert_entity(etype, formparams['eid'], rqlquery) |
289 entity.eid = eid = self._insert_entity(etype, formparams['eid'], rqlquery) |
292 elif rqlquery.edited: # edition of an existant entity |
290 elif rqlquery.edited: # edition of an existant entity |
293 self.check_concurrent_edition(formparams, eid) |
291 self.check_concurrent_edition(formparams, eid) |