doc/book/en/B051-define-entities.en.txt
author Sandrine Ribeau <sandrine.ribeau@logilab.fr>
Tue, 23 Dec 2008 13:38:02 -0800
changeset 291 87c8d96f6173
parent 229 767ff7f5d5a7
permissions -rw-r--r--
[doc] Renaming for advanced thematic.
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
``````````````````````
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
     8
It is possible to define in the schema *static* default values.
213f07dffde3 [doc] Translation to english.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 127
diff changeset
     9
It is also possible to define in the schema *dynamic* default values
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
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    58
* `primary`, indicates that an attribute or a relation has to be inserted
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    59
  in the simple or multiple editing forms. In the case of a relation,
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    60
  the related entity editing form will be included in the editing form.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    61
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    62
* `secondary`, indicates that an attribute or a relation has to be inserted
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    63
  in the simple editing form only. In the case of a relation, the related
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    64
  entity editing form sill be included in the editing form.
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    65
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    66
* `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
    67
  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
    68
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    69
* `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
    70
  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
    71
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    72
If necessarry, it is possible to overwrite the method  
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    73
`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
    74
a relation editing category.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    75
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    76
``add_related`` box management
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    77
``````````````````````````````
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    78
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    79
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
    80
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
    81
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
    82
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
    83
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
    84
following *rtags*:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    85
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    86
* `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
    87
  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
    88
  for this relation
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    89
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    90
* `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
    91
  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
    92
  entity and link to it automatically
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    94
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    95
If necessarry, it is possible to overwrite the method  
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    96
`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
    97
compute a relation creation category.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    98
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
    99
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
   100
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
   101
(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
   102
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   103
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   104
Filtering table forms management
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   105
````````````````````````````````
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   106
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   107
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
   108
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
   109
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   110
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
   111
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
   112
   others
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   113
3. for all the others variables defined in the original request:
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
   1. if the varaible is related to the main variable by at least one relation
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   116
   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
   117
      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
   118
      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
   119
      the vocabulary values returned
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   120
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   121
4. there is no others limitations to the `RQL`, it can include sorting, grouping
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   122
   conditions... Javascripts functions are used to regenerate a request based on the
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   123
   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
   124
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   125
The method ``filterform_vocabulary(rtype, x, var, rqlst, args, cachekey)`` takes 
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   126
the name of a relation and the target as parameters, which indicates of the
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   127
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
   128
has to return:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   129
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   130
* 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
   131
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   132
* 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
   133
  
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   134
  * 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
   135
  * 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
   136
    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
   137
229
767ff7f5d5a7 [doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 190
diff changeset
   138
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
   139
them by :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   140
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   141
* type
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   142
* priority
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   143
* state (in_state)
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   144
* tag (tags)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   145
* version (done_in)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   146
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   147
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
   148
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   149
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   150
    class Ticket(AnyEntity):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   151
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   152
	...
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   153
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   154
	def filterform_vocabulary(self, rtype, x, var, rqlst, args, cachekey):
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   155
	    _ = self.req._
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   156
	    if rtype == 'type':
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   157
		return 'string', [(x, _(x)) for x in ('bug', 'story')]
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   158
	    if rtype == 'priority':
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   159
		return 'string', [(x, _(x)) for x in ('minor', 'normal', 'important')]
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   160
	    if rtype == 'done_in':
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   161
		rql = insert_attr_select_relation(rqlst, var, rtype, 'num')
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   162
		return 'eid', self.req.execute(rql, args, cachekey)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   163
	    return super(Ticket, self).filterform_vocabulary(rtype, x, var, rqlst,
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   164
							     args, cachekey)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   165
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   166
.. note::
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   167
  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
   168