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