Coverage for gws-app/gws/base/model/validator.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-05 13:35 +0200

1"""Base model validator.""" 

2 

3import gws 

4 

5DEFAULT_MESSAGE_PREFIX = 'validationError_' 

6 

7 

8class Config(gws.Config): 

9 """Configuration for the model validator.""" 

10 

11 message: str = '' 

12 """Validation error message.""" 

13 forCreate: bool = True 

14 """The validator is applied when creating a new object.""" 

15 forUpdate: bool = True 

16 """The validator is applied when updating an existing object.""" 

17 

18 

19class Object(gws.ModelValidator): 

20 """Base model validator. 

21 

22 Provides the error message and the set of operations the validator applies to. 

23 Subclasses implement ``validate``. 

24 """ 

25 

26 def configure(self): 

27 self.message = self.cfg('message') or DEFAULT_MESSAGE_PREFIX + self.extType 

28 

29 self.ops = set() 

30 if self.cfg('forCreate'): 

31 self.ops.add(gws.ModelOperation.create) 

32 if self.cfg('forUpdate'): 

33 self.ops.add(gws.ModelOperation.update)