server/sources/native.py
branchstable
changeset 5131 88b5ca8da928
parent 5128 e5d300d75519
child 5168 1ab032df5ca3
equal deleted inserted replaced
5130:929984f017e6 5131:88b5ca8da928
   469         #    For instance, the BFSStorage will replace the `data`
   469         #    For instance, the BFSStorage will replace the `data`
   470         #    binary value with a Binary containing the destination path
   470         #    binary value with a Binary containing the destination path
   471         #    on the filesystem. To make the entity.data usage absolutely
   471         #    on the filesystem. To make the entity.data usage absolutely
   472         #    transparent, we'll have to reset entity.data to its binary
   472         #    transparent, we'll have to reset entity.data to its binary
   473         #    value once the SQL query will be executed
   473         #    value once the SQL query will be executed
   474         orig_values = {}
   474         restore_values = {}
   475         etype = entity.__regid__
   475         etype = entity.__regid__
   476         for attr, storage in self._storages.get(etype, {}).items():
   476         for attr, storage in self._storages.get(etype, {}).items():
   477             try:
   477             try:
   478                 if attr in entity.edited_attributes:
   478                 if attr in entity.edited_attributes:
   479                     orig_values[attr] = entity[attr]
       
   480                     handler = getattr(storage, 'entity_%s' % event)
   479                     handler = getattr(storage, 'entity_%s' % event)
   481                     handler(entity, attr)
   480                     real_value = handler(entity, attr)
       
   481                     restore_values[attr] = real_value
   482             except AttributeError:
   482             except AttributeError:
   483                 assert event == 'deleted'
   483                 assert event == 'deleted'
   484                 getattr(storage, 'entity_deleted')(entity, attr)
   484                 getattr(storage, 'entity_deleted')(entity, attr)
   485         try:
   485         try:
   486             yield # 2/ execute the source's instructions
   486             yield # 2/ execute the source's instructions
   487         finally:
   487         finally:
   488             # 3/ restore original values
   488             # 3/ restore original values
   489             for attr, value in orig_values.items():
   489             for attr, value in restore_values.items():
   490                 entity[attr] = value
   490                 entity[attr] = value
   491 
   491 
   492     def add_entity(self, session, entity):
   492     def add_entity(self, session, entity):
   493         """add a new entity to the source"""
   493         """add a new entity to the source"""
   494         with self._storage_handler(entity, 'added'):
   494         with self._storage_handler(entity, 'added'):