equal
deleted
inserted
replaced
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
6 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses |
7 """ |
7 """ |
8 __docformat__ = "restructuredtext en" |
8 __docformat__ = "restructuredtext en" |
9 |
9 |
10 from cubicweb.server import hook |
10 from cubicweb.server import hook |
|
11 from cubicweb.server.repository import ensure_card_respected |
11 |
12 |
12 class SetUseEmailRelationOp(hook.Operation): |
13 class SetUseEmailRelationOp(hook.Operation): |
13 """delay this operation to commit to avoid conflict with a late rql query |
14 """delay this operation to commit to avoid conflict with a late rql query |
14 already setting the relation |
15 already setting the relation |
15 """ |
16 """ |
21 return not any(e for e in self.entity.use_email |
22 return not any(e for e in self.entity.use_email |
22 if self.email.eid == e.eid) |
23 if self.email.eid == e.eid) |
23 |
24 |
24 def precommit_event(self): |
25 def precommit_event(self): |
25 if self.condition(): |
26 if self.condition(): |
26 self.session.unsafe_execute( |
27 # we've to handle cardinaly by ourselves since we're using unsafe_execute |
|
28 # but use session.execute and not session.unsafe_execute to check we |
|
29 # can change the relation |
|
30 ensure_card_respected(session.execute, session, |
|
31 self.fromeid, self.rtype, self.toeid) |
|
32 session.unsafe_execute( |
27 'SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % self.rtype, |
33 'SET X %s Y WHERE X eid %%(x)s, Y eid %%(y)s' % self.rtype, |
28 {'x': self.entity.eid, 'y': self.email.eid}, 'x') |
34 {'x': self.entity.eid, 'y': self.email.eid}, 'x') |
29 |
35 |
30 class SetPrimaryEmailRelationOp(SetUseEmailRelationOp): |
36 class SetPrimaryEmailRelationOp(SetUseEmailRelationOp): |
31 rtype = 'primary_email' |
37 rtype = 'primary_email' |