Coverage for gws-app/gws/plugin/model_validator/format/__init__.py: 100%
10 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Validator for correctly parsed values.
3When a value from the client (e.g. an integer) cannot be parsed by the field,
4the field stores ``gws.ErrorValue`` instead. This validator fails for such
5values, so that they are reported before the feature is written.
7Every field runs a default instance of this validator. A configured
8``format`` validator replaces the default one, e.g. to set a custom message.
10Example::
12 fields+ {
13 name "count"
14 type "integer"
15 validators+ { type "format" message "Please enter a whole number" }
16 }
17"""
19import gws
20import gws.base.model.validator
23@gws.ext.config.modelValidator('format')
24class Config(gws.base.model.validator.Config):
25 """Checks that a value could be parsed for the field type."""
27 pass
30@gws.ext.object.modelValidator('format')
31class Object(gws.base.model.validator.Object):
32 """Format validator object."""
34 def validate(self, field, feature, mc):
35 val = feature.attributes.get(field.name)
36 return val is not gws.ErrorValue