server/session.py
changeset 2968 0e3460341023
parent 2891 60afb9705035
parent 2940 db2fb2907389
child 3085 b415bca9a9ed
equal deleted inserted replaced
2902:dd9f2dd02f85 2968:0e3460341023
    73 
    73 
    74     def __str__(self):
    74     def __str__(self):
    75         return '<%ssession %s (%s 0x%x)>' % (self.cnxtype, self.user.login,
    75         return '<%ssession %s (%s 0x%x)>' % (self.cnxtype, self.user.login,
    76                                              self.id, id(self))
    76                                              self.id, id(self))
    77 
    77 
    78     def add_relation(self, fromeid, rtype, toeid):
    78     def _change_relation(self, cb, fromeid, rtype, toeid):
    79         if self.is_super_session:
    79         if self.is_super_session:
    80             self.repo.glob_add_relation(self, fromeid, rtype, toeid)
    80             cb(self, fromeid, rtype, toeid)
    81             return
    81             return
    82         self.is_super_session = True
    82         self.is_super_session = True
    83         try:
    83         try:
    84             self.repo.glob_add_relation(self, fromeid, rtype, toeid)
    84             cb(self, fromeid, rtype, toeid)
    85         finally:
    85         finally:
    86             self.is_super_session = False
    86             self.is_super_session = False
       
    87 
       
    88     def add_relation(self, fromeid, rtype, toeid):
       
    89         """provide direct access to the repository method to add a relation.
       
    90 
       
    91         This is equivalent to the following rql query:
       
    92 
       
    93           SET X rtype Y WHERE X eid  fromeid, T eid toeid
       
    94 
       
    95         without read security check but also all the burden of rql execution.
       
    96         You may use this in hooks when you know both eids of the relation you
       
    97         want to add.
       
    98         """
       
    99         self._change_relation(self.repo.glob_add_relation,
       
   100                               fromeid, rtype, toeid)
       
   101     def delete_relation(self, fromeid, rtype, toeid):
       
   102         """provide direct access to the repository method to delete a relation.
       
   103 
       
   104         This is equivalent to the following rql query:
       
   105 
       
   106           DELETE X rtype Y WHERE X eid  fromeid, T eid toeid
       
   107 
       
   108         without read security check but also all the burden of rql execution.
       
   109         You may use this in hooks when you know both eids of the relation you
       
   110         want to delete.
       
   111         """
       
   112         self._change_relation(self.repo.glob_delete_relation,
       
   113                               fromeid, rtype, toeid)
    87 
   114 
    88     def update_rel_cache_add(self, subject, rtype, object, symetric=False):
   115     def update_rel_cache_add(self, subject, rtype, object, symetric=False):
    89         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
   116         self._update_entity_rel_cache_add(subject, rtype, 'subject', object)
    90         if symetric:
   117         if symetric:
    91             self._update_entity_rel_cache_add(object, rtype, 'subject', subject)
   118             self._update_entity_rel_cache_add(object, rtype, 'subject', subject)
   561         return description
   588         return description
   562 
   589 
   563     # deprecated ###############################################################
   590     # deprecated ###############################################################
   564 
   591 
   565     @property
   592     @property
   566     @deprecated("[3.5] use session.vreg.schema")
   593     @deprecated("[3.6] use session.vreg.schema")
   567     def schema(self):
   594     def schema(self):
   568         return self.repo.schema
   595         return self.repo.schema
   569 
   596 
   570     @deprecated("[3.4] use vreg['etypes'].etype_class(etype)")
   597     @deprecated("[3.4] use vreg['etypes'].etype_class(etype)")
   571     def etype_class(self, etype):
   598     def etype_class(self, etype):