sobjects/email.py
branchstable
changeset 3315 59220b704562
parent 3248 db09803df8b2
child 4212 ab6573088b4a
equal deleted inserted replaced
3298:caef98aa4a98 3315:59220b704562
     7 """
     7 """
     8 __docformat__ = "restructuredtext en"
     8 __docformat__ = "restructuredtext en"
     9 
     9 
    10 from cubicweb.server.hooksmanager import Hook
    10 from cubicweb.server.hooksmanager import Hook
    11 from cubicweb.server.pool import PreCommitOperation
    11 from cubicweb.server.pool import PreCommitOperation
       
    12 from cubicweb.server.repository import ensure_card_respected
    12 
    13 
    13 class SetUseEmailRelationOp(PreCommitOperation):
    14 class SetUseEmailRelationOp(PreCommitOperation):
    14     """delay this operation to commit to avoid conflict with a late rql query
    15     """delay this operation to commit to avoid conflict with a late rql query
    15     already setting the relation
    16     already setting the relation
    16     """
    17     """
    24             {'x': self.fromeid, 'y': self.toeid}, 'x')
    25             {'x': self.fromeid, 'y': self.toeid}, 'x')
    25 
    26 
    26     def precommit_event(self):
    27     def precommit_event(self):
    27         session = self.session
    28         session = self.session
    28         if self.condition():
    29         if self.condition():
       
    30             # we've to handle cardinaly by ourselves since we're using unsafe_execute
       
    31             # but use session.execute and not session.unsafe_execute to check we
       
    32             # can change the relation
       
    33             ensure_card_respected(session.execute, session,
       
    34                                   self.fromeid, self.rtype, self.toeid)
    29             session.unsafe_execute(
    35             session.unsafe_execute(
    30                 'SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % self.rtype,
    36                 'SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % self.rtype,
    31                 {'x': self.fromeid, 'y': self.toeid}, 'x')
    37                 {'x': self.fromeid, 'y': self.toeid}, 'x')
    32 
    38 
    33 class SetPrimaryEmailRelationOp(SetUseEmailRelationOp):
    39 class SetPrimaryEmailRelationOp(SetUseEmailRelationOp):