server/hook.py
branchstable
changeset 8238 087bb529035c
parent 8032 bcb87336c7d2
child 8239 c6cdd060212e
equal deleted inserted replaced
8235:c2a91d6639d8 8238:087bb529035c
   113 containing the entity instance.
   113 containing the entity instance.
   114 
   114 
   115 - `before_add_entity`, `before_update_entity`:
   115 - `before_add_entity`, `before_update_entity`:
   116 
   116 
   117   On those events, you can access the modified attributes of the entity using
   117   On those events, you can access the modified attributes of the entity using
   118   the `entity.cw_edited` dictionnary. The values can be modified and the old
   118   the `entity.cw_edited` dictionary. The values can be modified and the old
   119   values can be retrieved.
   119   values can be retrieved.
   120 
   120 
   121   If you modify the `entity.cw_edited` dictionnary in the hook, that is before
   121   If you modify the `entity.cw_edited` dictionary in the hook, that is before
   122   the database operations take place, you will avoid the need to process a whole
   122   the database operations take place, you will avoid the need to process a whole
   123   new rql query and the underlying backend query (eg usually sql) will contain
   123   new rql query and the underlying backend query (eg usually sql) will contain
   124   the modified data. For example:
   124   the modified data. For example:
   125 
   125 
   126   .. sourcecode:: python
   126   .. sourcecode:: python
   143      old, new = entity.cw_edited.oldnewvalue('age')
   143      old, new = entity.cw_edited.oldnewvalue('age')
   144 
   144 
   145 - `after_add_entity`, `after_update_entity`
   145 - `after_add_entity`, `after_update_entity`
   146 
   146 
   147   On those events, you can get the list of attributes that were modified using
   147   On those events, you can get the list of attributes that were modified using
   148   the `entity.cw_edited` dictionnary, but you can not modify it or get the old
   148   the `entity.cw_edited` dictionary, but you can not modify it or get the old
   149   value of an attribute.
   149   value of an attribute.
   150 
   150 
   151 - `before_delete_entity`, `after_delete_entity`
   151 - `before_delete_entity`, `after_delete_entity`
   152 
   152 
   153   On those events, the entity has no `cw_edited` dictionnary.
   153   On those events, the entity has no `cw_edited` dictionary.
   154 
   154 
   155 .. note:: `self.entity.set_attributes(age=42)` will set the `age` attribute to
   155 .. note:: `self.entity.set_attributes(age=42)` will set the `age` attribute to
   156   42. But to do so, it will generate a rql query that will have to be processed,
   156   42. But to do so, it will generate a rql query that will have to be processed,
   157   hence may trigger some hooks, etc. This could lead to infinitely looping hooks.
   157   hence may trigger some hooks, etc. This could lead to infinitely looping hooks.
   158 
   158