author | Sandrine Ribeau <sandrine.ribeau@logilab.fr> |
Fri, 26 Dec 2008 12:00:47 -0800 | |
changeset 297 | ac86aaaaad08 |
parent 295 | 5da6a12e88fe |
child 302 | 3c5a1dace808 |
permissions | -rw-r--r-- |
114
9ecd54ea0634
[doc] more chapters
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
1 |
.. -*- coding: utf-8 -*- |
9ecd54ea0634
[doc] more chapters
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
2 |
|
9ecd54ea0634
[doc] more chapters
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
3 |
The Registry |
118
fae5651e7593
[doc] add another level to Foundation part of the book
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
114
diff
changeset
|
4 |
------------ |
114
9ecd54ea0634
[doc] more chapters
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
5 |
|
9ecd54ea0634
[doc] more chapters
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
6 |
[WRITE ME] |
9ecd54ea0634
[doc] more chapters
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
7 |
|
9ecd54ea0634
[doc] more chapters
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
8 |
* talk about the vreg singleton, appobjects, registration and selection |
9ecd54ea0634
[doc] more chapters
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff
changeset
|
9 |
|
123
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
10 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
11 |
Details of the recording process |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
12 |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
13 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
14 |
At startup, the `registry` or registers base, inspects a number of directories |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
15 |
looking for compatible classes definition. After a recording process, the objects |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
16 |
are assigned to registers so that they can be selected dynamically while the |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
17 |
application is running. |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
18 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
19 |
The base class of those objects is `AppRsetObject` (module `cubicweb.common.appobject`). |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
20 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
21 |
XXX registers example |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
22 |
XXX actual details of the recording process! |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
23 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
24 |
Runtime objects selection |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
25 |
~~~~~~~~~~~~~~~~~~~~~~~~~ |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
26 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
27 |
XXX tell why it's a cw foundation! |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
28 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
29 |
Application objects are stored in the registry using a two level hierarchy : |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
30 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
31 |
object's `__registry__` : object's `id` : [list of app objects] |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
32 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
33 |
The following rules are applied to select an object given a register and an id and an input context: |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
34 |
* each object has a selector |
295
5da6a12e88fe
[doc] Fix indentation issues.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
291
diff
changeset
|
35 |
|
123
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
36 |
- its selector may be derivated from a set of basic (or not :) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
37 |
selectors using `chainall` or `chainfirst` combinators |
295
5da6a12e88fe
[doc] Fix indentation issues.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents:
291
diff
changeset
|
38 |
|
123
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
39 |
* a selector return a score >= 0 |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
40 |
* a score of 0 means the objects can't be applied to the input context |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
41 |
* the object with the greatest score is selected. If multiple objects have an |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
42 |
identical score, one of them is selected randomly (this is usually a bug) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
43 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
44 |
The object's selector is the `__select__` class method on the object's class. |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
45 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
46 |
The score is used to choose the most pertinent objects where there are more than |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
47 |
one selectable object. For instance, if you're selecting the primary |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
48 |
(eg `id = 'primary'`) view (eg `__registry__ = 'view'`) for a result set containing |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
49 |
a `Card` entity, 2 objects will probably be selectable: |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
50 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
51 |
* the default primary view (`accepts = 'Any'`) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
52 |
* the specific `Card` primary view (`accepts = 'Card'`) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
53 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
54 |
This is because primary views are using the `accept_selector` which is considering the |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
55 |
`accepts` class attribute of the object's class. Other primary views specific to other |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
56 |
entity types won't be selectable in this case. And among selectable objects, the |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
57 |
accept selector will return a higher score the the second view since it's more |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
58 |
specific, so it will be selected as expected. |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
59 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
60 |
Usually, you won't define it directly but by defining the `__selectors__` tuple |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
61 |
on the class, with :: |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
62 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
63 |
__selectors__ = (sel1, sel2) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
64 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
65 |
which is equivalent to :: |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
66 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
67 |
__select__ = classmethod(chainall(sel1, sel2)) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
68 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
69 |
The former is prefered since it's shorter and it's ease overriding in |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
70 |
subclasses (you have access to sub-selectors instead of the wrapping function). |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
71 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
72 |
:chainall(selectors...): if one selector return 0, return 0, else return the sum of scores |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
73 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
74 |
:chainfirst(selectors...): return the score of the first selector which has a non zero score |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
75 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
76 |
XXX describe standard selector (link to generated api doc!) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
77 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
78 |
Example |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
79 |
```````` |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
80 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
81 |
Le but final : quand on est sur un Blog, on veut que le lien rss de celui-ci pointe |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
82 |
vers les entrées de ce blog, non vers l'entité blog elle-même. |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
83 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
84 |
L'idée générale pour résoudre ça : on définit une méthode sur les classes d'entité |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
85 |
qui renvoie l'url du flux rss pour l'entité en question. Avec une implémentation |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
86 |
par défaut sur AnyEntity et une implémentation particulière sur Blog qui fera ce |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
87 |
qu'on veut. |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
88 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
89 |
La limitation : on est embêté dans le cas ou par ex. on a un result set qui contient |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
90 |
plusieurs entités Blog (ou autre chose), car on ne sait pas sur quelle entité appeler |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
91 |
la méthode sus-citée. Dans ce cas, on va conserver le comportement actuel (eg appel |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
92 |
à limited_rql) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
93 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
94 |
Donc : on veut deux cas ici, l'un pour un rset qui contient une et une seule entité, |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
95 |
l'autre pour un rset qui contient plusieurs entité. |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
96 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
97 |
Donc... On a déja dans web/views/boxes.py la classe RSSIconBox qui fonctionne. Son |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
98 |
sélecteur :: |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
99 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
100 |
class RSSIconBox(ExtResourcesBoxTemplate): |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
101 |
"""just display the RSS icon on uniform result set""" |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
102 |
__selectors__ = ExtResourcesBoxTemplate.__selectors__ + (nfentity_selector,) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
103 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
104 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
105 |
indique qu'il prend en compte : |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
106 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
107 |
* les conditions d'apparition de la boite (faut remonter dans les classes parentes |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
108 |
pour voir le détail) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
109 |
* nfentity_selector, qui filtre sur des rset contenant une liste d'entité non finale |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
110 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
111 |
ça correspond donc à notre 2eme cas. Reste à fournir un composant plus spécifique |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
112 |
pour le 1er cas :: |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
113 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
114 |
class EntityRSSIconBox(RSSIconBox): |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
115 |
"""just display the RSS icon on uniform result set for a single entity""" |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
116 |
__selectors__ = RSSIconBox.__selectors__ + (onelinerset_selector,) |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
117 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
118 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
119 |
Ici, on ajoute onelinerset_selector, qui filtre sur des rset de taille 1. Il faut |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
120 |
savoir que quand on chaine des selecteurs, le score final est la somme des scores |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
121 |
renvoyés par chaque sélecteur (sauf si l'un renvoie zéro, auquel cas l'objet est |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
122 |
non sélectionnable). Donc ici, sur un rset avec plusieurs entités, onelinerset_selector |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
123 |
rendra la classe EntityRSSIconBox non sélectionnable, et on obtiendra bien la |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
124 |
classe RSSIconBox. Pour un rset avec une entité, la classe EntityRSSIconBox aura un |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
125 |
score supérieur à RSSIconBox et c'est donc bien elle qui sera sélectionnée. |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
126 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
127 |
Voili voilou, il reste donc pour finir tout ça : |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
128 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
129 |
* à définir le contenu de la méthode call de EntityRSSIconBox |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
130 |
* fournir l'implémentation par défaut de la méthode renvoyant l'url du flux rss sur |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
131 |
AnyEntity |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
132 |
* surcharger cette methode dans blog.Blog |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
133 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
134 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
135 |
When to use selectors? |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
136 |
``````````````````````` |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
137 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
138 |
Il faut utiliser les sélecteurs pour faire des choses différentes en |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
139 |
fonction de ce qu'on a en entrée. Dès qu'on a un "if" qui teste la |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
140 |
nature de `self.rset` dans un objet, il faut très sérieusement se |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
141 |
poser la question s'il ne vaut pas mieux avoir deux objets différent |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
142 |
avec des sélecteurs approprié. |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
143 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
144 |
If this is so fundamental, why don't I see them more often? |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
145 |
``````````````````````````````````````````````````````````` |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
146 |
|
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
147 |
Because you're usually using base classes which are hiding the plumbing |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
148 |
of __registry__ (almost always), id (often when using "standard" object), |
c5dd68070dea
move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents:
118
diff
changeset
|
149 |
register and selector. |