25 from warnings import warn |
25 from warnings import warn |
26 |
26 |
27 from logilab.common.deprecation import deprecated |
27 from logilab.common.deprecation import deprecated |
28 |
28 |
29 from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError, |
29 from cubicweb import (NoSelectableObject, ObjectNotFound, ValidationError, |
30 AuthenticationError, typed_eid, UndoTransactionException, |
30 AuthenticationError, UndoTransactionException, |
31 Forbidden) |
31 Forbidden) |
32 from cubicweb.utils import json_dumps |
32 from cubicweb.utils import json_dumps |
33 from cubicweb.predicates import (authenticated_user, anonymous_user, |
33 from cubicweb.predicates import (authenticated_user, anonymous_user, |
34 match_form_params) |
34 match_form_params) |
35 from cubicweb.web import Redirect, RemoteCallFailed |
35 from cubicweb.web import Redirect, RemoteCallFailed |
174 """ |
174 """ |
175 req = self._cw |
175 req = self._cw |
176 if not '__linkto' in req.form: |
176 if not '__linkto' in req.form: |
177 return |
177 return |
178 if eid is None: |
178 if eid is None: |
179 eid = typed_eid(req.form['eid']) |
179 eid = int(req.form['eid']) |
180 for linkto in req.list_form_param('__linkto', pop=True): |
180 for linkto in req.list_form_param('__linkto', pop=True): |
181 rtype, eids, target = linkto.split(':') |
181 rtype, eids, target = linkto.split(':') |
182 assert target in ('subject', 'object') |
182 assert target in ('subject', 'object') |
183 eids = eids.split('_') |
183 eids = eids.split('_') |
184 if target == 'subject': |
184 if target == 'subject': |
185 rql = 'SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype |
185 rql = 'SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % rtype |
186 else: |
186 else: |
187 rql = 'SET Y %s X WHERE X eid %%(x)s, Y eid %%(y)s' % rtype |
187 rql = 'SET Y %s X WHERE X eid %%(x)s, Y eid %%(y)s' % rtype |
188 for teid in eids: |
188 for teid in eids: |
189 req.execute(rql, {'x': eid, 'y': typed_eid(teid)}) |
189 req.execute(rql, {'x': eid, 'y': int(teid)}) |
190 |
190 |
191 |
191 |
192 def _validation_error(req, ex): |
192 def _validation_error(req, ex): |
193 req.cnx.rollback() |
193 req.cnx.rollback() |
194 ex.translate(req._) # translate messages using ui language |
194 ex.translate(req._) # translate messages using ui language |