doc/book/en/development/devcore/vreg.rst
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 03 Feb 2010 20:35:19 +0100
changeset 4444 fd80a06227b3
parent 4442 7bc0e4ed4109
child 4448 db672bef1078
permissions -rw-r--r--
document the ~ operator
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
4444
fd80a06227b3 document the ~ operator
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4442
diff changeset
    79
You can also "negate"  a selector by precedeing it by the `~` operator.
fd80a06227b3 document the ~ operator
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4442
diff changeset
    80
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    81
Of course you can use paren to balance expressions.
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    82
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    83
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
    84
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
    85
`__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
    86
will probably be selectable:
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    87
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
    88
* the default primary view (`__select__ = implements('Any')`), meaning
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
    89
  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
    90
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
    91
* the specific `Card` primary view (`__select__ = implements('Card')`,
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
    92
  meaning that the object is selectable for Card entities
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
    93
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
    94
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
    95
in this case. Among selectable objects, the implements selector will
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
    96
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
    97
so it will be selected as expected.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    98
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
Example
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   101
````````
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   102
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
   103
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
   104
entries, not to the blog entity itself.
2175
16d3c37c5d28 [doc] improvements
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2172
diff changeset
   105
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   106
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
   107
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
   108
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
   109
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
   110
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
   111
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
   112
aforementioned method. In this case, we keep the current behaviour
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
   113
(e.g : call to limited_rql).
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   114
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
   115
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
   116
for multi-entities rsets.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   117
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   118
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
   119
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   120
  class RSSIconBox(ExtResourcesBoxTemplate):
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   121
    """just display the RSS icon on uniform result set"""
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   122
    __select__ = ExtResourcesBoxTemplate.__select__ & non_final_entity()
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   123
3258
6536ee4f37f7 update the documentation
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 3048
diff changeset
   124
It takes into account:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   125
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   126
* 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
   127
  class hierarchy to know the details)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   128
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   129
* 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
   130
  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
   131
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   132
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
   133
component for the first case::
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   134
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   135
  class EntityRSSIconBox(RSSIconBox):
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   136
    """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
   137
    __select__ = RSSIconBox.__select__ & one_line_rset()
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   138
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   139
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
   140
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
   141
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
   142
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
   143
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
   144
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
   145
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
   146
3581
669854258b90 [doc] various fixes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3258
diff changeset
   147
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
   148
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   149
* fill in the call method of EntityRSSIconBox
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   150
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   151
* 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
   152
  stream url on AnyEntity
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   153
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   154
* redefine this method on Blog.
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   155
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   156
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
   157
``````````````````````
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
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
Selectors are to be used whenever arises the need of dispatching on the shape or
4442
7bc0e4ed4109 fix stupid sed
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4437
diff changeset
   160
content of a result set or whatever else context (value in request form params,
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
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
   162
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
   163
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
   164
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
   165
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
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
   168
```````````````````````````
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
   169
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
   170
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   171
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   172
Debugging
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
   173
`````````
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   174
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   175
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
   176
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
   177
(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
   178
manager to help with that.
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   179
3581
669854258b90 [doc] various fixes
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 3258
diff changeset
   180
Here is an example:
3048
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   181
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   182
.. sourcecode:: python
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   183
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
   184
     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
   185
     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
   186
         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
   187
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   188
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
   189
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
   190
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   191
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
   192
84c3e8f7e0cb translate bits of the doc
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 2545
diff changeset
   193
    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
   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
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
   196
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
   197
Take care not filtering-out messages whose log level is <= LOG_WARNING!