doc/book/en/B0031-define-entities.en.txt
author Stephanie Marcu <stephanie.marcu@logilab.fr>
Fri, 13 Feb 2009 16:16:15 +0100
changeset 620 be2dcc361105
parent 301 e47150482ac1
child 622 2d30c5e1a7d2
permissions -rw-r--r--
complete doc about rtags
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
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
be2dcc361105 complete doc about rtags
Stephanie Marcu <stephanie.marcu@logilab.fr>
parents: 301
diff changeset
    71
  of the current entity.
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    72
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    73
* `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
    74
  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
    75
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    76
* `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
    77
  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
    78
301
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 292
diff changeset
    79
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
    80
`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
    81
a relation editing category.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    82
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    83
``add_related`` box management
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    84
``````````````````````````````
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
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
    87
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
    88
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
    89
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
    90
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
    91
following *rtags*:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
    92
188
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    93
* `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
    94
  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
    95
  for this relation
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    96
97cc951f9f3c [doc] Started translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 130
diff changeset
    97
* `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
    98
  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
    99
  entity and link to it automatically
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   100
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   101
301
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 292
diff changeset
   102
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
   103
`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
   104
compute a relation creation category.
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   105
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   106
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
   107
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
   108
(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
   109
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   110
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   111
Filtering table forms management
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   112
````````````````````````````````
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
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
   115
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
   116
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   117
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
   118
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
   119
   others
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   120
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
   121
   
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   122
   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
   123
   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
   124
      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
   125
      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
   126
      the vocabulary values returned
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   127
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   128
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
   129
   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
   130
   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
   131
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   132
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
   133
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
   134
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
   135
has to return:
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   136
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   137
* 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
   138
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   139
* 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
   140
  
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   141
  * 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
   142
  * 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
   143
    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
   144
229
767ff7f5d5a7 [doc] Replace all : s/by example/for example/
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 190
diff changeset
   145
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
   146
them by :
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   147
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   148
* type
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   149
* priority
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   150
* state (in_state)
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   151
* tag (tags)
93
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   152
* version (done_in)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   153
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   154
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
   155
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   156
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   157
    class Ticket(AnyEntity):
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
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   161
	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
   162
	    _ = self.req._
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   163
	    if rtype == 'type':
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   164
		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
   165
	    if rtype == 'priority':
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   166
		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
   167
	    if rtype == 'done_in':
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   168
		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
   169
		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
   170
	    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
   171
							     args, cachekey)
9c919a47e140 [doc] total file reorganisation - phase 1 complete
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents:
diff changeset
   172
190
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   173
.. note::
1cca2d1aaaa3 [doc] Completed translation to english of entities definition section.
Sandrine Ribeau <sandrine.ribeau@logilab.fr>
parents: 188
diff changeset
   174
  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
   175