equal
deleted
inserted
replaced
40 return self.entity.cw_related_rql(self.tree_relation, self.parent_role) |
40 return self.entity.cw_related_rql(self.tree_relation, self.parent_role) |
41 |
41 |
42 The adapter object has ``self.entity`` attribute which represents the |
42 The adapter object has ``self.entity`` attribute which represents the |
43 entity being adapted. |
43 entity being adapted. |
44 |
44 |
|
45 .. Note:: |
|
46 |
|
47 Adapters came with the notion of service identified by the registry identifier |
|
48 of an adapters, hence dropping the need for explicit interface and the |
|
49 :class:`cubicweb.selectors.implements` selector. You should instead use |
|
50 :class:`cubicweb.selectors.is_instance` when you want to select on an entity |
|
51 type, or :class:`cubicweb.selectors.adaptable` when you want to select on a |
|
52 service. |
|
53 |
|
54 |
45 Specializing and binding an adapter |
55 Specializing and binding an adapter |
46 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
56 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
47 |
57 |
48 .. sourcecode:: python |
58 .. sourcecode:: python |
49 |
59 |
58 to help implement correct behaviour. |
68 to help implement correct behaviour. |
59 |
69 |
60 Here we provide a specific implementation which will be bound for |
70 Here we provide a specific implementation which will be bound for |
61 ``MyEntity`` entity type (the `adaptee`). |
71 ``MyEntity`` entity type (the `adaptee`). |
62 |
72 |
63 |
|
64 Selecting on an adapter |
|
65 ~~~~~~~~~~~~~~~~~~~~~~~ |
|
66 |
|
67 There is an ``adaptable`` selector which can be used instead of |
|
68 ``implements``. |
|
69 |
73 |
70 .. _interfaces_to_adapters: |
74 .. _interfaces_to_adapters: |
71 |
75 |
72 Converting code from Interfaces/Mixins to Adapters |
76 Converting code from Interfaces/Mixins to Adapters |
73 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
77 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
92 |
96 |
93 After: |
97 After: |
94 |
98 |
95 .. sourcecode:: python |
99 .. sourcecode:: python |
96 |
100 |
97 from cubicweb.selectors import adaptable, implements |
101 from cubicweb.selectors import adaptable, is_instance |
98 from cubicweb.entities.adapters import ITreeAdapter |
102 from cubicweb.entities.adapters import ITreeAdapter |
99 |
103 |
100 class MyEntityITreeAdapter(ITreeAdapter): |
104 class MyEntityITreeAdapter(ITreeAdapter): |
101 __select__ = implements('MyEntity') |
105 __select__ = is_instance('MyEntity') |
102 |
106 |
103 class ITreeView(EntityView): |
107 class ITreeView(EntityView): |
104 __select__ = adaptable('ITree') |
108 __select__ = adaptable('ITree') |
105 def cell_call(self, row, col): |
109 def cell_call(self, row, col): |
106 entity = self.cw_rset.get_entity(row, col) |
110 entity = self.cw_rset.get_entity(row, col) |