server/hook.py
branchstable
changeset 5060 ee3b856e1406
parent 5019 72734c210836
child 5067 adc2122eed03
equal deleted inserted replaced
5059:1d5c81588144 5060:ee3b856e1406
   448         return self.session.repo.config
   448         return self.session.repo.config
   449 
   449 
   450 set_log_methods(Operation, getLogger('cubicweb.session'))
   450 set_log_methods(Operation, getLogger('cubicweb.session'))
   451 
   451 
   452 
   452 
       
   453 def set_operation(session, datakey, value, opcls, **opkwargs):
       
   454     """Search for session.transaction_data[`datakey`] (expected to be a set):
       
   455 
       
   456     * if found, simply append `value`
       
   457 
       
   458     * else, initialize it to set([`value`]) and instantiate the given `opcls`
       
   459       operation class with additional keyword arguments.
       
   460 
       
   461     You should use this instead of creating on operation for each `value`,
       
   462     since handling operations becomes coslty on massive data import.
       
   463     """
       
   464     try:
       
   465         session.transaction_data[datakey].add(value)
       
   466     except KeyError:
       
   467         print 'init', datakey
       
   468         opcls(session, *opkwargs)
       
   469         session.transaction_data[datakey] = set((value,))
       
   470 
       
   471 
   453 class LateOperation(Operation):
   472 class LateOperation(Operation):
   454     """special operation which should be called after all possible (ie non late)
   473     """special operation which should be called after all possible (ie non late)
   455     operations
   474     operations
   456     """
   475     """
   457     def insert_index(self):
   476     def insert_index(self):