doc/book/en/B0031-define-entities.en.txt
author Emile Anclin <emile.anclin@logilab.fr>
Wed, 01 Apr 2009 19:40:51 +0200
changeset 1207 33d0e08a931a
parent 622 2d30c5e1a7d2
child 1353 fb5f014b861d
permissions -rw-r--r--
[doc] trying to get it a little bit more readable
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     2
130
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
     3
Parametrization and specific extensions
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
     4
---------------------------------------
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
     5
130
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
     6
Dynamic default values
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
     7
``````````````````````
1207
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
     8
It is possible to define *static* default values in the schema.
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
     9
It is also possible to define *dynamic* default values
130
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    10
by defining in the entity class a method `default_<attribut name>` for
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    11
a given attribute.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    12
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    13
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    14
Loaded attributes and default sorting management
130
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    15
````````````````````````````````````````````````
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    16
130
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    17
* The class attribute `fetch_attrs` allows to defined in an entity class
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    18
  a list of names of attributes or relations that should be automatically
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    19
  loaded when we recover the entities of this type. In the case of relations,
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    20
  we are limited to *subject of cardinality `?` or `1`* relations.
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    21
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    22
* The class method `fetch_order(attr, var)` expects an attribute (or relation)
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    23
  name as a parameter and a variable name, and it should return a string
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    24
  to use in the requirement `ORDER BY` of an RQL query to automatically
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    25
  sort the list of entities of such type according to this attribute, or
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    26
  `None` if we do not want to sort on the attribute given in the parameter.
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    27
  By default, the entities are sorted according to their creation date.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    28
130
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    29
* The class method `fetch_unrelated_order(attr, var)` is similar to the 
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    30
  method `fetch_order` except that it is essentially used to control
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    31
  the sorting of drop-down lists enabling relations creation in 
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    32
  the editing view of an entity.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    33
130
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    34
The function `fetch_config(fetchattrs, mainattr=None)` simplifies the
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    35
definition of the attributes to load and the sorting by returning a 
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    36
list of attributes to pre-load (considering automatically the attributes
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    37
of `AnyEntity`) and a sorting function based on the main attribute
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    38
(the second parameter if specified otherwisethe first attribute from
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    39
the list `fetchattrs`).
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
    40
This function is defined in `cubicweb.entities`.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    41
229
767ff7f5d5a7 [doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 190
diff changeset
    42
For example: ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    43
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    44
  class Transition(AnyEntity):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    45
    """..."""
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    46
    id = 'Transition'
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    47
    fetch_attrs, fetch_order = fetch_config(['name'])
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    48
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    49
Indicates that for the entity type "Transition", you have to pre-load
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    50
the attribute `name` and sort by default on this attribute.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    51
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    52
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    53
Editing forms management
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    54
````````````````````````
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    55
It is possible to manage attributes/relations in the simple or multiple
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    56
editing form thanks to the following *rtags*: 
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    57
620
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    58
* `primary`, indicates that an attribute or a relation has to be
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    59
  inserted **in the simple or multiple editing forms**. In the case of
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    60
  a relation, the related entity editing form will be included in the
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    61
  editing form and represented as a combobox. Each item of the
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    62
  combobox is a link to an existing entity.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    63
620
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    64
* `secondary`, indicates that an attribute or a relation has to be
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    65
  inserted **in the simple editing form only**. In the case of a
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    66
  relation, the related entity editing form will be included in the
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    67
  editing form and represented as a combobox. Each item of the combobox
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    68
  is a link to an existing entity.
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    69
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    70
* `inlineview`, includes the target entity's form in the editing form
622
2d30c5e1a7d2 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 620
diff changeset
    71
  of the current entity. It allows to create the target entity in the
2d30c5e1a7d2 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 620
diff changeset
    72
  same time as the current entity.
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    73
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    74
* `generic`, indicates that a relation has to be inserted in the simple
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    75
  editing form, in the generic box of relation creation.
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    76
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    77
* `generated`, indicates that an attribute is dynamically computed
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    78
  or other,  and that it should not be displayed in the editing form.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    79
301
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 292
diff changeset
    80
If necessary, it is possible to overwrite the method  
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    81
`relation_category(rtype, x='subject')` to dynamically compute
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    82
a relation editing category.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    83
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    84
``add_related`` box management
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    85
``````````````````````````````
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    86
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    87
The box ``add_related`` is an automatic box that allows to create
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    88
an entity automatically related to the initial entity (context in
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    89
which the box is displayed). By default, the links generated in this
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    90
box are computed from the schema properties of the displayed entity,
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    91
but it is possible to explicitely specify them thanks to the
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    92
following *rtags*:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    93
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    94
* `link`, indicates that a relation is in general created pointing
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    95
  to an existing entity and that we should not to display a link
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    96
  for this relation
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    97
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    98
* `create`, indicates that a relation is in general created pointing
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    99
  to new entities and that we should display a link to create a new
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
   100
  entity and link to it automatically
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   101
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   102
301
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 292
diff changeset
   103
If necessary, it is possible to overwrite the method  
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
   104
`relation_mode(rtype, targettype, x='subject')` to dynamically
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
   105
compute a relation creation category.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   106
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   107
Please note that if at least one action belongs to the `addrelated` category,
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
   108
the automatic behavior is desactivated in favor of an explicit behavior
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
   109
(e.g. display of `addrelated` category actions only).
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   110
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   111
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   112
Filtering table forms management
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   113
````````````````````````````````
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   114
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   115
By default, the view ``table`` manages automatically a filtering
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   116
form of its content. The algorithm is as follows:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   117
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   118
1. we consider that the first column contains the entities to constraint
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   119
2. we collect the first entity of the table (row 0) to represent all the 
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   120
   others
1207
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   121
3. for all the other variables defined in the original request:
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   122
   
1207
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   123
   1. if the variable is related to the main variable by at least one relation
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   124
   2. we call the method ``filterform_vocabulary(rtype, x)`` on the entity,
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   125
      if nothing is returned (meaning a tuple `Non`, see below), we go to the
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   126
      next variable, otherwise a form filtering element is created based on
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   127
      the vocabulary values returned
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   128
1207
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   129
4. there are no other limitations to the `RQL`, it can include sorting, grouping
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   130
   conditions... JavaScript functions are used to regenerate a request based on the
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   131
   initial request and on the selected values from the filtering form.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   132
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   133
The method ``filterform_vocabulary(rtype, x, var, rqlst, args, cachekey)`` takes 
1207
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   134
the name of a relation and the target as parameters,
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   135
[XXX what does it mean ?]
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   136
 which indicates of the
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   137
entity on which we apply the method is subject or object of the relation. It
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   138
has to return:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   139
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   140
* a 2-uple of None if it does not know how to handle the relation
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   141
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   142
* a type and a list containing the vocabulary
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   143
  
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   144
  * the list has to contain couples (value, label)
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   145
  * the type indicates if the value designate an integer (`type == 'int'`),
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   146
    a string (`type =='string'` or a non-final relation (`type == 'eid'`)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   147
229
767ff7f5d5a7 [doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 190
diff changeset
   148
For example in our application managing tickets, we want to be able to filter
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   149
them by :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   150
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   151
* type
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   152
* priority
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   153
* state (in_state)
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   154
* tag (tags)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   155
* version (done_in)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   156
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   157
For that we define the following method: ::
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   158
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   159
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   160
    class Ticket(AnyEntity):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   161
1207
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   162
	    ...
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   163
1207
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   164
    	def filterform_vocabulary(self, rtype, x, var, rqlst, args, cachekey):
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   165
	        _ = self.req._
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   166
	        if rtype == 'type':
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   167
        		return 'string', [(x, _(x)) for x in ('bug', 'story')]
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   168
	        if rtype == 'priority':
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   169
    	    	return 'string', [(x, _(x)) for x in ('minor', 'normal', 'important')]
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   170
    	    if rtype == 'done_in':
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   171
	        	rql = insert_attr_select_relation(rqlst, var, rtype, 'num')
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   172
		        return 'eid', self.req.execute(rql, args, cachekey)
33d0e08a931a [doc] trying to get it a little bit more readable
Emile Anclin <emile.anclin@logilab.fr>
parents: 622
diff changeset
   173
	        return super(Ticket, self).filterform_vocabulary(rtype, x, var, rqlst,
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   174
							     args, cachekey)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   175
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   176
.. note::
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   177
  Filtering on state and tags is automatically installed, no need to handle it.
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   178