server/session.py
changeset 8780 d3e49fc74e79
parent 8779 9b2f68916474
child 8781 f1a5792dd8a3
equal deleted inserted replaced
8779:9b2f68916474 8780:d3e49fc74e79
   451         # while undesired
   451         # while undesired
   452         tx.ctx_count = 1
   452         tx.ctx_count = 1
   453         # share pending_operations, else operation added in the hi-jacked
   453         # share pending_operations, else operation added in the hi-jacked
   454         # session such as SendMailOp won't ever be processed
   454         # session such as SendMailOp won't ever be processed
   455         tx.pending_operations = self.pending_operations
   455         tx.pending_operations = self.pending_operations
   456         # everything in transaction_data should be copied back but the entity
   456         # everything in tx.data should be copied back but the entity
   457         # type cache we don't want to avoid security pb
   457         # type cache we don't want to avoid security pb
   458         tx.data = self.transaction_data.copy()
   458         tx.data = self._tx.data.copy()
   459         tx.data.pop('ecache', None)
   459         tx.data.pop('ecache', None)
   460         return session
   460         return session
   461 
   461 
   462     def add_relation(self, fromeid, rtype, toeid):
   462     def add_relation(self, fromeid, rtype, toeid):
   463         """provide direct access to the repository method to add a relation.
   463         """provide direct access to the repository method to add a relation.
   603 
   603 
   604     def deleted_in_transaction(self, eid):
   604     def deleted_in_transaction(self, eid):
   605         """return True if the entity of the given eid is being deleted in the
   605         """return True if the entity of the given eid is being deleted in the
   606         current transaction
   606         current transaction
   607         """
   607         """
   608         return eid in self.transaction_data.get('pendingeids', ())
   608         return eid in self._tx.data.get('pendingeids', ())
   609 
   609 
   610     def added_in_transaction(self, eid):
   610     def added_in_transaction(self, eid):
   611         """return True if the entity of the given eid is being created in the
   611         """return True if the entity of the given eid is being created in the
   612         current transaction
   612         current transaction
   613         """
   613         """
   614         return eid in self.transaction_data.get('neweids', ())
   614         return eid in self._tx.data.get('neweids', ())
   615 
   615 
   616     def rtype_eids_rdef(self, rtype, eidfrom, eidto):
   616     def rtype_eids_rdef(self, rtype, eidfrom, eidto):
   617         # use type_and_source_from_eid instead of type_from_eid for optimization
   617         # use type_and_source_from_eid instead of type_from_eid for optimization
   618         # (avoid two extra methods call)
   618         # (avoid two extra methods call)
   619         subjtype = self.repo.type_and_source_from_eid(eidfrom, self)[0]
   619         subjtype = self.repo.type_and_source_from_eid(eidfrom, self)[0]
   919             self._tx.ctx_count -= 1
   919             self._tx.ctx_count -= 1
   920 
   920 
   921     def _touch(self):
   921     def _touch(self):
   922         """update latest session usage timestamp and reset mode to read"""
   922         """update latest session usage timestamp and reset mode to read"""
   923         self.timestamp = time()
   923         self.timestamp = time()
   924         self.local_perm_cache.clear() # XXX simply move in transaction_data, no?
   924         self.local_perm_cache.clear() # XXX simply move in tx.data, no?
   925 
   925 
   926     # shared data handling ###################################################
   926     # shared data handling ###################################################
   927 
   927 
   928     def get_shared_data(self, key, default=None, pop=False, txdata=False):
   928     def get_shared_data(self, key, default=None, pop=False, txdata=False):
   929         """return value associated to `key` in session data"""
   929         """return value associated to `key` in session data"""
   930         if txdata:
   930         if txdata:
   931             data = self.transaction_data
   931             data = self._tx.data
   932         else:
   932         else:
   933             data = self.data
   933             data = self.data
   934         if pop:
   934         if pop:
   935             return data.pop(key, default)
   935             return data.pop(key, default)
   936         else:
   936         else:
   937             return data.get(key, default)
   937             return data.get(key, default)
   938 
   938 
   939     def set_shared_data(self, key, value, txdata=False):
   939     def set_shared_data(self, key, value, txdata=False):
   940         """set value associated to `key` in session data"""
   940         """set value associated to `key` in session data"""
   941         if txdata:
   941         if txdata:
   942             self.transaction_data[key] = value
   942             self._tx.data[key] = value
   943         else:
   943         else:
   944             self.data[key] = value
   944             self.data[key] = value
   945 
   945 
   946     # server-side service call #################################################
   946     # server-side service call #################################################
   947 
   947 
   960         # XXX session level caching may be a pb with multiple repository
   960         # XXX session level caching may be a pb with multiple repository
   961         #     instances, but 1. this is probably not the only one :$ and 2. it
   961         #     instances, but 1. this is probably not the only one :$ and 2. it
   962         #     may be an acceptable risk. Anyway we could activate it or not
   962         #     may be an acceptable risk. Anyway we could activate it or not
   963         #     according to a configuration option
   963         #     according to a configuration option
   964         try:
   964         try:
   965             self.transaction_data['ecache'].setdefault(entity.eid, entity)
   965             self._tx.data['ecache'].setdefault(entity.eid, entity)
   966         except KeyError:
   966         except KeyError:
   967             self.transaction_data['ecache'] = ecache = {}
   967             self._tx.data['ecache'] = ecache = {}
   968             ecache[entity.eid] = entity
   968             ecache[entity.eid] = entity
   969 
   969 
   970     def entity_cache(self, eid):
   970     def entity_cache(self, eid):
   971         return self.transaction_data['ecache'][eid]
   971         return self._tx.data['ecache'][eid]
   972 
   972 
   973     def cached_entities(self):
   973     def cached_entities(self):
   974         return self.transaction_data.get('ecache', {}).values()
   974         return self._tx.data.get('ecache', {}).values()
   975 
   975 
   976     def drop_entity_cache(self, eid=None):
   976     def drop_entity_cache(self, eid=None):
   977         if eid is None:
   977         if eid is None:
   978             self.transaction_data.pop('ecache', None)
   978             self._tx.data.pop('ecache', None)
   979         else:
   979         else:
   980             del self.transaction_data['ecache'][eid]
   980             del self._tx.data['ecache'][eid]
   981 
   981 
   982     def from_controller(self):
   982     def from_controller(self):
   983         """return the id (string) of the controller issuing the request (no
   983         """return the id (string) of the controller issuing the request (no
   984         sense here, always return 'view')
   984         sense here, always return 'view')
   985         """
   985         """
  1219     def ertype_supports_undo(self, ertype):
  1219     def ertype_supports_undo(self, ertype):
  1220         return self.undo_actions  and ertype not in NO_UNDO_TYPES
  1220         return self.undo_actions  and ertype not in NO_UNDO_TYPES
  1221 
  1221 
  1222     def transaction_uuid(self, set=True):
  1222     def transaction_uuid(self, set=True):
  1223         try:
  1223         try:
  1224             return self.transaction_data['tx_uuid']
  1224             return self._tx.data['tx_uuid']
  1225         except KeyError:
  1225         except KeyError:
  1226             if not set:
  1226             if not set:
  1227                 return
  1227                 return
  1228             self.transaction_data['tx_uuid'] = uuid = uuid4().hex
  1228             self._tx.data['tx_uuid'] = uuid = uuid4().hex
  1229             self.repo.system_source.start_undoable_transaction(self, uuid)
  1229             self.repo.system_source.start_undoable_transaction(self, uuid)
  1230             return uuid
  1230             return uuid
  1231 
  1231 
  1232     def transaction_inc_action_counter(self):
  1232     def transaction_inc_action_counter(self):
  1233         num = self.transaction_data.setdefault('tx_action_count', 0) + 1
  1233         num = self._tx.data.setdefault('tx_action_count', 0) + 1
  1234         self.transaction_data['tx_action_count'] = num
  1234         self._tx.data['tx_action_count'] = num
  1235         return num
  1235         return num
  1236 
  1236 
  1237     # querier helpers #########################################################
  1237     # querier helpers #########################################################
  1238 
  1238 
  1239     @property
  1239     @property