47 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
47 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
48 |
48 |
49 .. index:: |
49 .. index:: |
50 vregistry: registration_callback |
50 vregistry: registration_callback |
51 |
51 |
52 On startup |cubicweb| loads application objects defined in its library |
52 On startup, |cubicweb| loads application objects defined in its library |
53 and in cubes used by the instance. Application objects from the |
53 and in cubes used by the instance. Application objects from the |
54 library are loaded first, then those provided by cubes are loaded in |
54 library are loaded first, then those provided by cubes are loaded in |
55 dependency order (e.g. if your cube depends on an other, objects from |
55 dependency order (e.g. if your cube depends on an other, objects from |
56 the dependency will be loaded first). Cube's modules or packages where |
56 the dependency will be loaded first). The layout of the modules or packages |
57 appobject are looked for is explained in :ref:`cubelayout`. |
57 in a cube is explained in :ref:`cubelayout`. |
58 |
58 |
59 For each module: |
59 For each module: |
60 |
60 |
61 * by default all objects are registered automatically |
61 * by default all objects are registered automatically |
62 |
62 |
142 |
142 |
143 - 0 score means the object doesn't apply to this context |
143 - 0 score means the object doesn't apply to this context |
144 |
144 |
145 - else, the higher the score, the better the object suits the context |
145 - else, the higher the score, the better the object suits the context |
146 |
146 |
147 * the object with the higher score is selected. |
147 * the object with the highest score is selected. |
148 |
148 |
149 .. Note:: |
149 .. Note:: |
150 |
150 |
151 When no score is higher than the others, an exception is raised in development |
151 When no single object has the highest score, an exception is raised in development |
152 mode to let you know that the engine was not able to identify the view to |
152 mode to let you know that the engine was not able to identify the view to |
153 apply. This error is silenced in production mode and one of the objects with |
153 apply. This error is silenced in production mode and one of the objects with |
154 the higher score is picked. |
154 the highest score is picked. |
155 |
155 |
156 In such cases you would need to review your design and make sure your selectors |
156 In such cases you would need to review your design and make sure |
157 or appobjects are properly defined. |
157 your selectors or appobjects are properly defined. Such an error is |
158 |
158 typically caused by either forgetting to change the __regid__ in a |
159 For instance, if you are selecting the primary (eg `__regid__ = |
159 derived class, or by having copy-pasted some code. |
160 'primary'`) view (eg `__registry__ = 'views'`) for a result set |
160 |
|
161 For instance, if you are selecting the primary (`__regid__ = |
|
162 'primary'`) view (`__registry__ = 'views'`) for a result set |
161 containing a `Card` entity, two objects will probably be selectable: |
163 containing a `Card` entity, two objects will probably be selectable: |
162 |
164 |
163 * the default primary view (`__select__ = implements('Any')`), meaning |
165 * the default primary view (`__select__ = implements('Any')`), meaning |
164 that the object is selectable for any kind of entity type |
166 that the object is selectable for any kind of entity type |
165 |
167 |
166 * the specific `Card` primary view (`__select__ = implements('Card')`, |
168 * the specific `Card` primary view (`__select__ = implements('Card')`, |
167 meaning that the object is selectable for Card entities |
169 meaning that the object is selectable for Card entities |
168 |
170 |
169 Other primary views specific to other entity types won't be selectable in this |
171 Other primary views specific to other entity types won't be selectable in this |
170 case. Among selectable objects, the implements selector will return a higher |
172 case. Among selectable objects, the `implements('Card')` selector will return a higher |
171 score than the second view since it's more specific, so it will be selected as |
173 score since it's more specific, so the correct view will be selected as expected. |
172 expected. |
|
173 |
174 |
174 .. _SelectionAPI: |
175 .. _SelectionAPI: |
175 |
176 |
176 API for objects selections |
177 API for objects selections |
177 ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
178 ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
178 |
179 |
179 Here is the selection API you'll get on every registry. Some of them, as the |
180 Here is the selection API you'll get on every registry. Some of them, as the |
180 'etypes' registry, containing entity classes, extend it. In those methods, |
181 'etypes' registry, containing entity classes, extend it. In those methods, |
181 `*args, **kwargs` is what we call the **context**. Those arguments are given to |
182 `*args, **kwargs` is what we call the **context**. Those arguments are given to |
182 selectors that will inspect there content and return a score accordingly. |
183 selectors that will inspect their content and return a score accordingly. |
183 |
184 |
184 .. automethod:: cubicweb.vregistry.Registry.select |
185 .. automethod:: cubicweb.vregistry.Registry.select |
185 |
186 |
186 .. automethod:: cubicweb.vregistry.Registry.select_or_none |
187 .. automethod:: cubicweb.vregistry.Registry.select_or_none |
187 |
188 |