31 |
31 |
32 def precommit_event(self): |
32 def precommit_event(self): |
33 # recheck pending eids |
33 # recheck pending eids |
34 if self.session.deleted_in_transaction(self.eid): |
34 if self.session.deleted_in_transaction(self.eid): |
35 return |
35 return |
|
36 if self.rtype in self.session.transaction_data.get('pendingrtypes', ()): |
|
37 return |
36 if self.session.unsafe_execute(*self._rql()).rowcount < 1: |
38 if self.session.unsafe_execute(*self._rql()).rowcount < 1: |
37 etype = self.session.describe(self.eid)[0] |
39 etype = self.session.describe(self.eid)[0] |
38 _ = self.session._ |
40 _ = self.session._ |
39 msg = _('at least one relation %(rtype)s is required on %(etype)s (%(eid)s)') |
41 msg = _('at least one relation %(rtype)s is required on %(etype)s (%(eid)s)') |
40 msg %= {'rtype': _(self.rtype), 'etype': _(etype), 'eid': self.eid} |
42 msg %= {'rtype': _(self.rtype), 'etype': _(etype), 'eid': self.eid} |
85 opcls(self._cw, rtype=rtype, eid=eid) |
87 opcls(self._cw, rtype=rtype, eid=eid) |
86 |
88 |
87 def after_add_entity(self): |
89 def after_add_entity(self): |
88 eid = self.entity.eid |
90 eid = self.entity.eid |
89 eschema = self.entity.e_schema |
91 eschema = self.entity.e_schema |
90 for rschema, targetschemas, x in eschema.relation_definitions(): |
92 for rschema, targetschemas, role in eschema.relation_definitions(): |
91 # skip automatically handled relations |
93 # skip automatically handled relations |
92 if rschema.type in DONT_CHECK_RTYPES_ON_ADD: |
94 if rschema.type in DONT_CHECK_RTYPES_ON_ADD: |
93 continue |
95 continue |
94 if x == 'subject': |
96 if role == 'subject': |
95 subjtype = eschema |
|
96 objtype = targetschemas[0].type |
|
97 cardindex = 0 |
|
98 opcls = _CheckSRelationOp |
97 opcls = _CheckSRelationOp |
99 else: |
98 else: |
100 subjtype = targetschemas[0].type |
|
101 objtype = eschema |
|
102 cardindex = 1 |
|
103 opcls = _CheckORelationOp |
99 opcls = _CheckORelationOp |
104 card = rschema.rproperty(subjtype, objtype, 'cardinality') |
100 rdef = rschema.role_rdef(eschema, targetschemas[0], role) |
105 if card[cardindex] in '1+': |
101 if rdef.role_cardinality(role) in '1+': |
106 self.checkrel_if_necessary(opcls, rschema.type, eid) |
102 self.checkrel_if_necessary(opcls, rschema.type, eid) |
107 |
103 |
108 def before_delete_relation(self): |
104 def before_delete_relation(self): |
109 rtype = self.rtype |
105 rtype = self.rtype |
110 if rtype in DONT_CHECK_RTYPES_ON_DEL: |
106 if rtype in DONT_CHECK_RTYPES_ON_DEL: |
171 def __call__(self): |
167 def __call__(self): |
172 schema = self._cw.vreg.schema |
168 schema = self._cw.vreg.schema |
173 entity = self.entity |
169 entity = self.entity |
174 for attr in entity.edited_attributes: |
170 for attr in entity.edited_attributes: |
175 if schema.rschema(attr).final: |
171 if schema.rschema(attr).final: |
176 constraints = [c for c in entity.e_schema.constraints(attr) |
172 constraints = [c for c in entity.rdef(attr).constraints |
177 if isinstance(c, RQLVocabularyConstraint)] |
173 if isinstance(c, RQLVocabularyConstraint)] |
178 if constraints: |
174 if constraints: |
179 _CheckConstraintsOp(self._cw, constraints=constraints, |
175 _CheckConstraintsOp(self._cw, constraints=constraints, |
180 rdef=(entity.eid, attr, None)) |
176 rdef=(entity.eid, attr, None)) |
181 |
177 |