doc/book/en/BXXX-registry.en.txt
author Nicolas Chauvat <nicolas.chauvat@logilab.fr>
Mon, 22 Dec 2008 17:02:01 +0100
changeset 255 5d2804b9a28c
parent 127 ae611743f5c6
permissions -rw-r--r--
[doc] add internal links from book abstract
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:
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
c5dd68070dea move registry details into their own chapter, add missing classmethod() for __select__ definition
Sylvain Thenault <sylvain.thenault@logilab.fr>
parents: 118
diff changeset
    35
  - 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
    36
    selectors using `chainall` or `chainfirst` combinators
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
* 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
    38
* 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
    39
* 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
    40
  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
    41
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
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
    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 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
    45
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
    46
(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
    47
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
    48
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
* 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
    50
* 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
    51
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
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
    53
`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
    54
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
    55
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
    56
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
    57
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
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
    59
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
    60
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
  __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
    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
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
    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
  __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
    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
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
    68
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
    69
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
: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
    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
: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
    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
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
    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
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
    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
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
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
    80
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
    81
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
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
    83
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
    84
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
    85
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
    86
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
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
    88
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
    89
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
    90
à 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
    91
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
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
    93
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
    94
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
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
    96
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
    97
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
  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
    99
    """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
   100
    __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
   101
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
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
   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
* 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
   106
  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
   107
* 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
   108
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
ç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
   110
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
   111
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
  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
   113
    """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
   114
    __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
   115
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
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
   118
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
   119
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
   120
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
   121
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
   122
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
   123
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
   124
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
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
   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
* à 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
   128
* 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
   129
  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
   130
* 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
   131
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
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
   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
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
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
   137
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
   138
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
   139
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
   140
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
   141
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
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
   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
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
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
   146
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
   147
register and selector.