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

17 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2025-10-16 23:09 +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 """Error message prefix for validation errors.""" 

13 forCreate: bool = True 

14 """If True, the validator is applied when creating a new object.""" 

15 forUpdate: bool = True 

16 """If True, the validator is applied when updating an existing object.""" 

17 

18 

19class Object(gws.ModelValidator): 

20 def configure(self): 

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

22 

23 self.ops = set() 

24 if self.cfg('forCreate'): 

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

26 if self.cfg('forUpdate'): 

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