Coverage for gws-app / gws / plugin / model_validator / number_range / __init__.py: 0%
28 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-03 10:12 +0100
« prev ^ index » next coverage.py v7.13.4, created at 2026-03-03 10:12 +0100
1"""Validator for number ranges."""
3from typing import Optional
5import gws
6import gws.base.model.validator
8gws.ext.new.modelValidator('numberRange')
11class Config(gws.base.model.validator.Config):
12 """Validator for number ranges."""
14 min: Optional[gws.ext.config.modelValue]
15 """Minimum value for the range."""
16 max: Optional[gws.ext.config.modelValue]
17 """Maximum value for the range."""
20class Object(gws.base.model.validator.Object):
21 minVal: Optional[gws.ModelValue]
22 maxVal: Optional[gws.ModelValue]
24 def configure(self):
25 self.minVal = self.create_child_if_configured(gws.ext.object.modelValue, self.cfg('min'))
26 self.maxVal = self.create_child_if_configured(gws.ext.object.modelValue, self.cfg('max'))
28 def validate(self, field, feature, mc):
29 val = feature.attributes.get(field.name)
30 if not isinstance(val, (int, float)):
31 return False
33 if self.minVal:
34 v = self.minVal.compute(field, feature, mc)
35 if val < v:
36 return False
38 if self.maxVal:
39 v = self.maxVal.compute(field, feature, mc)
40 if val > v:
41 return False
43 return True