equal
deleted
inserted
replaced
48 .. sourcecode:: python |
48 .. sourcecode:: python |
49 |
49 |
50 from cubicweb.entities.adapters import ITreeAdapter |
50 from cubicweb.entities.adapters import ITreeAdapter |
51 |
51 |
52 class MyEntityITreeAdapter(ITreeAdapter): |
52 class MyEntityITreeAdapter(ITreeAdapter): |
53 __select__ = implements('MyEntity') |
53 __select__ = is_instance('MyEntity') |
54 tree_relation = 'filed_under' |
54 tree_relation = 'filed_under' |
55 |
55 |
56 The ITreeAdapter here provides a default implementation. The |
56 The ITreeAdapter here provides a default implementation. The |
57 tree_relation class attribute is actually used by this implementation |
57 tree_relation class attribute is actually used by this implementation |
58 to help implement correct behaviour. |
58 to help implement correct behaviour. |
122 def bar(self, *args): |
122 def bar(self, *args): |
123 raise NotImplementedError |
123 raise NotImplementedError |
124 |
124 |
125 class MyEntity(AnyEntity): |
125 class MyEntity(AnyEntity): |
126 __regid__ = 'MyEntity' |
126 __regid__ = 'MyEntity' |
|
127 __implements__ = AnyEntity.__implements__ + (IFoo,) |
127 |
128 |
128 def bar(self, *args): |
129 def bar(self, *args): |
129 return sum(captain.age for captain in self.captains) |
130 return sum(captain.age for captain in self.captains) |
130 |
131 |
131 class FooView(EntityView): |
132 class FooView(EntityView): |
140 |
141 |
141 .. sourcecode:: python |
142 .. sourcecode:: python |
142 |
143 |
143 class IFooAdapter(EntityAdapter): |
144 class IFooAdapter(EntityAdapter): |
144 __regid__ = 'IFoo' |
145 __regid__ = 'IFoo' |
|
146 __select__ = is_instance('MyEntity') |
145 |
147 |
146 def bar(self, *args): |
148 def bar(self, *args): |
147 return sum(captain.age for captain in self.entity.captains) |
149 return sum(captain.age for captain in self.entity.captains) |
148 |
150 |
149 class FooView(EntityView): |
151 class FooView(EntityView): |