19 |
19 |
20 __docformat__ = "restructuredtext en" |
20 __docformat__ = "restructuredtext en" |
21 |
21 |
22 from warnings import warn |
22 from warnings import warn |
23 |
23 |
|
24 from logilab.common.deprecation import deprecated |
|
25 |
24 from rql.utils import rqlvar_maker |
26 from rql.utils import rqlvar_maker |
25 |
27 |
26 from cubicweb import Binary, ValidationError, typed_eid |
28 from cubicweb import Binary, ValidationError, typed_eid |
27 from cubicweb.view import EntityAdapter, implements_adapter_compat |
29 from cubicweb.view import EntityAdapter, implements_adapter_compat |
28 from cubicweb.selectors import is_instance |
30 from cubicweb.selectors import is_instance |
33 |
35 |
34 class IEditControlAdapter(EntityAdapter): |
36 class IEditControlAdapter(EntityAdapter): |
35 __needs_bw_compat__ = True |
37 __needs_bw_compat__ = True |
36 __regid__ = 'IEditControl' |
38 __regid__ = 'IEditControl' |
37 __select__ = is_instance('Any') |
39 __select__ = is_instance('Any') |
|
40 |
|
41 @deprecated() |
|
42 def __init__(self, _cw, **kwargs): |
|
43 warn('[3.14] IEditControlAdapter is deprecated, override EditController' |
|
44 ' using match_edited_type or match_form_id selectors for example.', |
|
45 DeprecationWarning) |
|
46 super(IEditControlAdapter, self).__init__(_cw, **kwargs) |
38 |
47 |
39 @implements_adapter_compat('IEditControl') |
48 @implements_adapter_compat('IEditControl') |
40 def after_deletion_path(self): |
49 def after_deletion_path(self): |
41 """return (path, parameters) which should be used as redirect |
50 """return (path, parameters) which should be used as redirect |
42 information when this entity is being deleted |
51 information when this entity is being deleted |
45 if parent is not None: |
54 if parent is not None: |
46 return parent.rest_path(), {} |
55 return parent.rest_path(), {} |
47 return str(self.entity.e_schema).lower(), {} |
56 return str(self.entity.e_schema).lower(), {} |
48 |
57 |
49 @implements_adapter_compat('IEditControl') |
58 @implements_adapter_compat('IEditControl') |
50 def pre_web_edit(self, form): |
59 def pre_web_edit(self): |
51 """callback called by the web editcontroller when an entity will be |
60 """callback called by the web editcontroller when an entity will be |
52 created/modified, to let a chance to do some entity specific stuff. |
61 created/modified, to let a chance to do some entity specific stuff. |
53 |
62 |
54 Do nothing by default. |
63 Do nothing by default. |
55 """ |
64 """ |
165 """edit / create / copy an entity and return its eid""" |
174 """edit / create / copy an entity and return its eid""" |
166 etype = formparams['__type'] |
175 etype = formparams['__type'] |
167 entity = self._cw.vreg['etypes'].etype_class(etype)(self._cw) |
176 entity = self._cw.vreg['etypes'].etype_class(etype)(self._cw) |
168 entity.eid = valerror_eid(formparams['eid']) |
177 entity.eid = valerror_eid(formparams['eid']) |
169 is_main_entity = self._cw.form.get('__maineid') == formparams['eid'] |
178 is_main_entity = self._cw.form.get('__maineid') == formparams['eid'] |
170 if is_main_entity: |
|
171 formid = self._cw.form.get('__form_id', 'edition') |
|
172 else: |
|
173 # XXX inlined forms formid should be saved in a different formparams entry |
|
174 # inbetween, use cubicweb standard formid for inlined forms |
|
175 formid = 'edition' |
|
176 form = self._cw.vreg['forms'].select(formid, self._cw, entity=entity) |
|
177 # let a chance to do some entity specific stuff |
179 # let a chance to do some entity specific stuff |
178 entity.cw_adapt_to('IEditControl').pre_web_edit(form) |
180 entity.cw_adapt_to('IEditControl').pre_web_edit() |
179 # create a rql query from parameters |
181 # create a rql query from parameters |
180 rqlquery = RqlQuery() |
182 rqlquery = RqlQuery() |
181 # process inlined relations at the same time as attributes |
183 # process inlined relations at the same time as attributes |
182 # this will generate less rql queries and might be useful in |
184 # this will generate less rql queries and might be useful in |
183 # a few dark corners |
185 # a few dark corners |
|
186 if is_main_entity: |
|
187 formid = self._cw.form.get('__form_id', 'edition') |
|
188 else: |
|
189 # XXX inlined forms formid should be saved in a different formparams entry |
|
190 # inbetween, use cubicweb standard formid for inlined forms |
|
191 formid = 'edition' |
|
192 form = self._cw.vreg['forms'].select(formid, self._cw, entity=entity) |
184 eid = form.actual_eid(entity.eid) |
193 eid = form.actual_eid(entity.eid) |
185 try: |
194 try: |
186 editedfields = formparams['_cw_entity_fields'] |
195 editedfields = formparams['_cw_entity_fields'] |
187 except KeyError: |
196 except KeyError: |
188 try: |
197 try: |