author | Sylvain Thénault <sylvain.thenault@logilab.fr> |
Wed, 23 Sep 2009 11:22:08 +0200 | |
changeset 3411 | c867a096e11c |
parent 3258 | 6536ee4f37f7 |
child 3581 | 669854258b90 |
permissions | -rw-r--r-- |
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
1 |
. -*- coding: utf-8 -*- |
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
2 |
|
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
3 |
The VRegistry |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
4 |
-------------- |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
5 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
6 |
The recording process on startup |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
7 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
8 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
9 |
Details of the recording process |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
10 |
```````````````````````````````` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
11 |
|
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
12 |
XXX this part needs to be updated and checked |
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
13 |
|
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
14 |
* by default all objects are registered automatically |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
15 |
|
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
16 |
* if some objects have to replace other objects or be included only if a |
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
17 |
condition is true, |
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
18 |
- explicitly register the object by defining `registration_callback(vreg)` |
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
19 |
- call registration methods on objects listed in the vreg registry |
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
20 |
|
2042
d524ae901b31
Add a note concerning explicit object registering.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
1714
diff
changeset
|
21 |
.. note:: |
d524ae901b31
Add a note concerning explicit object registering.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
1714
diff
changeset
|
22 |
Once the function `registration_callback(vreg)` is implemented, all the objects |
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
23 |
have to be explicitly registered as it disables the automatic object registering. |
2172
cf8f9180e63e
delete-trailing-whitespace
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2043
diff
changeset
|
24 |
|
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
25 |
Examples: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
26 |
|
2545
f8246ed962f6
[doc] replace code-block with sourcecode
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2175
diff
changeset
|
27 |
.. sourcecode:: python |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
28 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
29 |
# web/views/basecomponents.py |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
30 |
def registration_callback(vreg): |
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
31 |
# register everything in the module except SeeAlsoComponent |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
32 |
vreg.register_all(globals().values(), __name__, (SeeAlsoVComponent,)) |
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
33 |
# conditionally register SeeAlsoVComponent |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
34 |
if 'see_also' in vreg.schema: |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
35 |
vreg.register(SeeAlsoVComponent) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
36 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
37 |
# goa/appobjects/sessions.py |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
38 |
def registration_callback(vreg): |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
39 |
vreg.register(SessionsCleaner) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
40 |
vreg.register(GAEAuthenticationManager, clear=True) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
41 |
vreg.register(GAEPersistentSessionManager, clear=True) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
42 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
43 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
44 |
API d'enregistrement des objets |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
45 |
``````````````````````````````` |
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
46 |
|
2545
f8246ed962f6
[doc] replace code-block with sourcecode
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2175
diff
changeset
|
47 |
.. sourcecode:: python |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
48 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
49 |
register(obj, registryname=None, oid=None, clear=False) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
50 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
51 |
register_all(objects, modname, butclasses=()) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
52 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
53 |
unregister(obj, registryname=None) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
54 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
55 |
register_and_replace(obj, replaced, registryname=None) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
56 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
57 |
register_if_interface_found(obj, ifaces, **kwargs) |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
58 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
59 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
60 |
Runtime objects selection |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
61 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
62 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
63 |
Defining selectors |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
64 |
`````````````````` |
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
65 |
|
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
66 |
The object's selector is defined by its `__select__` class attribute. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
67 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
68 |
When two selectors are combined using the `&` operator (formerly `chainall`), it |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
69 |
means that both should return a positive score. On success, the sum of scores is returned. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
70 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
71 |
When two selectors are combined using the `|` operator (former `chainfirst`), it |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
72 |
means that one of them should return a positive score. On success, the first |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
73 |
positive score is returned. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
74 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
75 |
Of course you can use paren to balance expressions. |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
76 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
77 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
78 |
For instance, if you are selecting the primary (eg `id = 'primary'`) view (eg |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
79 |
`__registry__ = 'view'`) for a result set containing a `Card` entity, 2 objects |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
80 |
will probably be selectable: |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
81 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
82 |
* the default primary view (`__select__ = implements('Any')`), meaning |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
83 |
that the object is selectable for any kind of entity type |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
84 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
85 |
* the specific `Card` primary view (`__select__ = implements('Card')`, |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
86 |
meaning that the object is selectable for Card entities |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
87 |
|
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
88 |
Other primary views specific to other entity types won't be selectable |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
89 |
in this case. Among selectable objects, the implements selector will |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
90 |
return a higher score than the second view since it's more specific, |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
91 |
so it will be selected as expected. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
92 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
93 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
94 |
Example |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
95 |
```````` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
96 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
97 |
The goal: when on a Blog, one wants the RSS link to refer to blog |
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
98 |
entries, not to the blog entity itself. |
2175
16d3c37c5d28
[doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
2172
diff
changeset
|
99 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
100 |
To do that, one defines a method on entity classes that returns the |
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
101 |
RSS stream url for a given entity. The default implementation on |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
102 |
AnyEntity and a specific implementation on Blog will do what we want. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
103 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
104 |
But when we have a result set containing several Blog entities (or |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
105 |
different entities), we don't know on which entity to call the |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
106 |
aforementioned method. In this case, we keep the current behaviour |
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
107 |
(e.g : call to limited_rql). |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
108 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
109 |
Hence we have two cases here, one for a single-entity rsets, the other |
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
110 |
for multi-entities rsets. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
111 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
112 |
In web/views/boxes.py lies the RSSIconBox class. Look at its selector :: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
113 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
114 |
class RSSIconBox(ExtResourcesBoxTemplate): |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
115 |
"""just display the RSS icon on uniform result set""" |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
116 |
__select__ = ExtResourcesBoxTemplate.__select__ & non_final_entity() |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
117 |
|
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
118 |
It takes into account: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
119 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
120 |
* the inherited selection criteria (one has to look them up in the |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
121 |
class hierarchy to know the details) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
122 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
123 |
* non_final_entity, which filters on rsets containing non final |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
124 |
entities (a 'final entity' being synonym for entity attribute) |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
125 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
126 |
This matches our second case. Hence we have to provide a specific |
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
127 |
component for the first case:: |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
128 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
129 |
class EntityRSSIconBox(RSSIconBox): |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
130 |
"""just display the RSS icon on uniform result set for a single entity""" |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
131 |
__select__ = RSSIconBox.__select__ & one_line_rset() |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
132 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
133 |
Here, one adds the one_line_rset selector, which filters result sets |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
134 |
of size 1. When one chains selectors, the final score is the sum of |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
135 |
the score of each individual selector (unless one of them returns 0, |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
136 |
in which case the object is non selectable). Thus, on a multiple |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
137 |
entities selector, one_line_rset makes the EntityRSSIconBox class non |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
138 |
selectable. For an rset with one entity, the EntityRSSIconBox class |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
139 |
will have a higher score then RSSIconBox, which is what we wanted. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
140 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
141 |
Of course, once this is done, you have to :: |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
142 |
|
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
143 |
* fill in the call method of EntityRSSIconBox |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
144 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
145 |
* provide the default implementation of the method returning the RSS |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
146 |
stream url on AnyEntity |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
147 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
148 |
* redefine this method on Blog. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
149 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
150 |
When to use selectors? |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
151 |
``````````````````````` |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
152 |
|
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
153 |
Selectors are to be used whenever arises the need of dispatching on |
3258
6536ee4f37f7
update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
3048
diff
changeset
|
154 |
the shape or content of a result set. That is, almost all the time. |
1714
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
155 |
|
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
156 |
Debugging |
a721966779be
new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff
changeset
|
157 |
````````` |
3048
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
158 |
|
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
159 |
Once in a while, one needs to understand why a view (or any AppObject) |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
160 |
is, or is not selected appropriately. Looking at which selectors fired |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
161 |
(or did not) is the way. There exists a traced_selection context |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
162 |
manager to help with that. |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
163 |
|
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
164 |
Here is an example :: |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
165 |
|
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
166 |
.. sourcecode:: python |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
167 |
|
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
168 |
def possible_objects(self, registry, *args, **kwargs): |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
169 |
"""return an iterator on possible objects in a registry for this result set |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
170 |
|
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
171 |
actions returned are classes, not instances |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
172 |
""" |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
173 |
from cubicweb.selectors import traced_selection |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
174 |
with traced_selection(): |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
175 |
for vobjects in self.registry(registry).values(): |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
176 |
try: |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
177 |
yield self.select(vobjects, *args, **kwargs) |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
178 |
except NoSelectableObject: |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
179 |
continue |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
180 |
|
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
181 |
Don't forget the 'from __future__ import with_statement' at the module |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
182 |
top-level. |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
183 |
|
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
184 |
This will yield additional WARNINGs in the logs, like this:: |
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
185 |
|
84c3e8f7e0cb
translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents:
2545
diff
changeset
|
186 |
2009-01-09 16:43:52 - (cubicweb.selectors) WARNING: selector one_line_rset returned 0 for <class 'cubicweb.web.views.basecomponents.WFHistoryVComponent'> |