equal
deleted
inserted
replaced
33 __regid__ = 'person_age_range' |
33 __regid__ = 'person_age_range' |
34 __select__ = Hook.__select__ & is_instance('Person') |
34 __select__ = Hook.__select__ & is_instance('Person') |
35 events = ('before_add_entity', 'before_update_entity') |
35 events = ('before_add_entity', 'before_update_entity') |
36 |
36 |
37 def __call__(self): |
37 def __call__(self): |
38 if 'age' in self.entity.cw_edited: |
38 if 'age' in self.entity.cw_edited: |
39 if 0 <= self.entity.age <= 120: |
39 if 0 <= self.entity.age <= 120: |
40 return |
40 return |
41 msg = self._cw._('age must be between 0 and 120') |
41 msg = self._cw._('age must be between 0 and 120') |
42 raise ValidationError(self.entity.eid, {'age': msg}) |
42 raise ValidationError(self.entity.eid, {'age': msg}) |
43 |
43 |
44 In our example the base `__select__` is augmented with an `is_instance` selector |
44 In our example the base `__select__` is augmented with an `is_instance` selector |
45 matching the desired entity type. |
45 matching the desired entity type. |
46 |
46 |
47 The `events` tuple is used to specify that our hook should be called before the |
47 The `events` tuple is used to specify that our hook should be called before the |