equal
deleted
inserted
replaced
15 |
15 |
16 from cubicweb import Binary, ValidationError, typed_eid |
16 from cubicweb import Binary, ValidationError, typed_eid |
17 from cubicweb.web import INTERNAL_FIELD_VALUE, RequestError, NothingToEdit, ProcessFormError |
17 from cubicweb.web import INTERNAL_FIELD_VALUE, RequestError, NothingToEdit, ProcessFormError |
18 from cubicweb.web.views import basecontrollers, autoform |
18 from cubicweb.web.views import basecontrollers, autoform |
19 |
19 |
|
20 def valerror_eid(eid): |
|
21 try: |
|
22 return typed_eid(eid) |
|
23 except (ValueError, TypeError): |
|
24 return eid |
20 |
25 |
21 class RqlQuery(object): |
26 class RqlQuery(object): |
22 def __init__(self): |
27 def __init__(self): |
23 self.edited = [] |
28 self.edited = [] |
24 self.restrictions = [] |
29 self.restrictions = [] |
108 if toinsert: |
113 if toinsert: |
109 autoform.insert_relations(self._cw, toinsert) |
114 autoform.insert_relations(self._cw, toinsert) |
110 self._cw.remove_pending_operations() |
115 self._cw.remove_pending_operations() |
111 if self.errors: |
116 if self.errors: |
112 errors = dict((f.name, unicode(ex)) for f, ex in self.errors) |
117 errors = dict((f.name, unicode(ex)) for f, ex in self.errors) |
113 raise ValidationError(form.get('__maineid'), errors) |
118 raise ValidationError(valerror_eid(form.get('__maineid')), errors) |
114 |
119 |
115 def _insert_entity(self, etype, eid, rqlquery): |
120 def _insert_entity(self, etype, eid, rqlquery): |
116 rql = rqlquery.insert_query(etype) |
121 rql = rqlquery.insert_query(etype) |
117 try: |
122 try: |
118 # get the new entity (in some cases, the type might have |
123 # get the new entity (in some cases, the type might have |
164 for field in field.actual_fields(form): |
169 for field in field.actual_fields(form): |
165 if field.has_been_modified(form): |
170 if field.has_been_modified(form): |
166 self.handle_formfield(form, field, rqlquery) |
171 self.handle_formfield(form, field, rqlquery) |
167 if self.errors: |
172 if self.errors: |
168 errors = dict((f.role_name(), unicode(ex)) for f, ex in self.errors) |
173 errors = dict((f.role_name(), unicode(ex)) for f, ex in self.errors) |
169 raise ValidationError(entity.eid, errors) |
174 raise ValidationError(valerror_eid(entity.eid), errors) |
170 if eid is None: # creation or copy |
175 if eid is None: # creation or copy |
171 entity.eid = self._insert_entity(etype, formparams['eid'], rqlquery) |
176 entity.eid = self._insert_entity(etype, formparams['eid'], rqlquery) |
172 elif rqlquery.edited: # edition of an existant entity |
177 elif rqlquery.edited: # edition of an existant entity |
173 self._update_entity(eid, rqlquery) |
178 self._update_entity(eid, rqlquery) |
174 if is_main_entity: |
179 if is_main_entity: |