You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is actually pretty closely related to #53, and may even be a duplicate of
that issue. When using a core validator, there is no way to get back to the
original attributes. For our use case, we actually want the metadata, rather
than an actual message. There are a couple of workarounds, such as the
following
However, this feels like it should be more core than that. I could submit a PR,
that updates most of the validator/invalid pairs to be like the following.
fromvoluptuousimportInvalid, MultipleInvalid, SchemaclassRangeInvalid(Invalid):
"""The value is not in given range."""def__init__(self, message, min=None, max=None, min_included=None, max_included=None, *args, **kwargs):
super(RangeInvalid, self).__init__(message, *args, **kwargs)
self.min=minself.max=maxself.min_included=min_includedself.max_included=max_includedclassRange(object):
def__init__(self, min=None, max=None, min_included=True, max_included=True, msg=None):
self.min=minself.max=maxself.min_included=min_includedself.max_included=max_includedself.msg=msgdef__call__(self, v):
ifself.min_included:
ifself.minisnotNoneandnotv>=self.min:
raiseRangeInvalid(
self.msgor'value must be at least %s'%self.min,
min=self.min,
max=self.max,
min_included=self.min_included,
max_included=self.max_included)
else:
ifself.minisnotNoneandnotv>self.min:
raiseRangeInvalid(
self.msgor'value must be higher than %s'%self.min,
min=self.min,
max=self.max,
min_included=self.min_included,
max_included=self.max_included)
ifself.max_included:
ifself.maxisnotNoneandnotv<=self.max:
raiseRangeInvalid(
self.msgor'value must be at most %s'%self.max,
min=self.min,
max=self.max,
min_included=self.min_included,
max_included=self.max_included)
else:
ifself.maxisnotNoneandnotv<self.max:
raiseRangeInvalid(
self.msgor'value must be lower than %s'%self.max,
min=self.min,
max=self.max,
min_included=self.min_included,
max_included=self.max_included)
returnvs=Schema(Range(0, 10))
try:
s(42)
exceptMultipleInvalidaserrors:
e=errors.errors[0]
print(e.min, e.max) # 0 10
The text was updated successfully, but these errors were encountered:
This is actually pretty closely related to #53, and may even be a duplicate of
that issue. When using a core validator, there is no way to get back to the
original attributes. For our use case, we actually want the metadata, rather
than an actual message. There are a couple of workarounds, such as the
following
However, this feels like it should be more core than that. I could submit a PR,
that updates most of the validator/invalid pairs to be like the following.
The text was updated successfully, but these errors were encountered: