doc/book/en/B0031-define-entities.en.txt
changeset 1207 33d0e08a931a
parent 622 2d30c5e1a7d2
child 1353 fb5f014b861d
equal deleted inserted replaced
1206:6db7addc2869 1207:33d0e08a931a
     3 Parametrization and specific extensions
     3 Parametrization and specific extensions
     4 ---------------------------------------
     4 ---------------------------------------
     5 
     5 
     6 Dynamic default values
     6 Dynamic default values
     7 ``````````````````````
     7 ``````````````````````
     8 It is possible to define in the schema *static* default values.
     8 It is possible to define *static* default values in the schema.
     9 It is also possible to define in the schema *dynamic* default values
     9 It is also possible to define *dynamic* default values
    10 by defining in the entity class a method `default_<attribut name>` for
    10 by defining in the entity class a method `default_<attribut name>` for
    11 a given attribute.
    11 a given attribute.
    12 
    12 
    13 
    13 
    14 Loaded attributes and default sorting management
    14 Loaded attributes and default sorting management
   116 form of its content. The algorithm is as follows:
   116 form of its content. The algorithm is as follows:
   117 
   117 
   118 1. we consider that the first column contains the entities to constraint
   118 1. we consider that the first column contains the entities to constraint
   119 2. we collect the first entity of the table (row 0) to represent all the 
   119 2. we collect the first entity of the table (row 0) to represent all the 
   120    others
   120    others
   121 3. for all the others variables defined in the original request:
   121 3. for all the other variables defined in the original request:
   122    
   122    
   123    1. if the varaible is related to the main variable by at least one relation
   123    1. if the variable is related to the main variable by at least one relation
   124    2. we call the method ``filterform_vocabulary(rtype, x)`` on the entity,
   124    2. we call the method ``filterform_vocabulary(rtype, x)`` on the entity,
   125       if nothing is returned (meaning a tuple `Non`, see below), we go to the
   125       if nothing is returned (meaning a tuple `Non`, see below), we go to the
   126       next variable, otherwise a form filtering element is created based on
   126       next variable, otherwise a form filtering element is created based on
   127       the vocabulary values returned
   127       the vocabulary values returned
   128 
   128 
   129 4. there is no others limitations to the `RQL`, it can include sorting, grouping
   129 4. there are no other limitations to the `RQL`, it can include sorting, grouping
   130    conditions... Javascripts functions are used to regenerate a request based on the
   130    conditions... JavaScript functions are used to regenerate a request based on the
   131    initial request and on the selected values from the filtering form.
   131    initial request and on the selected values from the filtering form.
   132 
   132 
   133 The method ``filterform_vocabulary(rtype, x, var, rqlst, args, cachekey)`` takes 
   133 The method ``filterform_vocabulary(rtype, x, var, rqlst, args, cachekey)`` takes 
   134 the name of a relation and the target as parameters, which indicates of the
   134 the name of a relation and the target as parameters,
       
   135 [XXX what does it mean ?]
       
   136  which indicates of the
   135 entity on which we apply the method is subject or object of the relation. It
   137 entity on which we apply the method is subject or object of the relation. It
   136 has to return:
   138 has to return:
   137 
   139 
   138 * a 2-uple of None if it does not know how to handle the relation
   140 * a 2-uple of None if it does not know how to handle the relation
   139 
   141 
   155 For that we define the following method: ::
   157 For that we define the following method: ::
   156 
   158 
   157 
   159 
   158     class Ticket(AnyEntity):
   160     class Ticket(AnyEntity):
   159 
   161 
   160 	...
   162 	    ...
   161 
   163 
   162 	def filterform_vocabulary(self, rtype, x, var, rqlst, args, cachekey):
   164     	def filterform_vocabulary(self, rtype, x, var, rqlst, args, cachekey):
   163 	    _ = self.req._
   165 	        _ = self.req._
   164 	    if rtype == 'type':
   166 	        if rtype == 'type':
   165 		return 'string', [(x, _(x)) for x in ('bug', 'story')]
   167         		return 'string', [(x, _(x)) for x in ('bug', 'story')]
   166 	    if rtype == 'priority':
   168 	        if rtype == 'priority':
   167 		return 'string', [(x, _(x)) for x in ('minor', 'normal', 'important')]
   169     	    	return 'string', [(x, _(x)) for x in ('minor', 'normal', 'important')]
   168 	    if rtype == 'done_in':
   170     	    if rtype == 'done_in':
   169 		rql = insert_attr_select_relation(rqlst, var, rtype, 'num')
   171 	        	rql = insert_attr_select_relation(rqlst, var, rtype, 'num')
   170 		return 'eid', self.req.execute(rql, args, cachekey)
   172 		        return 'eid', self.req.execute(rql, args, cachekey)
   171 	    return super(Ticket, self).filterform_vocabulary(rtype, x, var, rqlst,
   173 	        return super(Ticket, self).filterform_vocabulary(rtype, x, var, rqlst,
   172 							     args, cachekey)
   174 							     args, cachekey)
   173 
   175 
   174 .. note::
   176 .. note::
   175   Filtering on state and tags is automatically installed, no need to handle it.
   177   Filtering on state and tags is automatically installed, no need to handle it.
   176 
   178