doc/book/en/B4030-registry.en.txt
author Emile Anclin <emile.anclin@logilab.fr>
Wed, 01 Apr 2009 17:31:20 +0200
changeset 1205 79d33f7db590
parent 302 3c5a1dace808
permissions -rw-r--r--
[doc] some more small improvements
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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:
302
3c5a1dace808 [doc] small text improvement
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 295
diff changeset
    34
* each object has a selector which may be built from a set of basic (or not :)
295
5da6a12e88fe [doc] Fix indentation issues.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 291
diff changeset
    35
  
302
3c5a1dace808 [doc] small text improvement
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 295
diff changeset
    36
  selectors using `chainall` or `chainfirst` combinators
295
5da6a12e88fe [doc] Fix indentation issues.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 291
diff changeset
    37
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
    38
* 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
    39
* 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
    40
* 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
    41
  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
    42
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
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
    44
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
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
    46
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
    47
(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
    48
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
    49
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
* 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
    51
* 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
    52
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
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
    54
`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
    55
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
    56
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
    57
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
    58
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
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
    60
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
    61
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
  __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
    63
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
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
    65
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
  __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
    67
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
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
    69
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
    70
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
: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
    72
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
: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
    74
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
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
    76
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
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
    78
````````
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
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
    81
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
    82
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
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
    84
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
    85
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
    86
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
    87
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
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
    89
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
    90
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
    91
à 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
    92
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
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
    94
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
    95
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
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
    97
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
    98
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
  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
   100
    """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
   101
    __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
   102
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
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
   105
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
* 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
   107
  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
   108
* 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
   109
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
ç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
   111
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
   112
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
  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
   114
    """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
   115
    __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
   116
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
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
   119
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
   120
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
   121
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
   122
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
   123
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
   124
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
   125
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
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
   127
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
* à 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
   129
* 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
   130
  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
   131
* 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
   132
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
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
   135
```````````````````````
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
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
   138
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
   139
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
   140
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
   141
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
   142
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
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
   144
```````````````````````````````````````````````````````````
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
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
   147
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
   148
register and selector.