I do it this (very dumb and probably dangerous) way:
----- %< -----
class RequiredSchemaNode(colander.SchemaNode):
def deserialize(self, *args, **kw):
try:
return super(RequiredSchemaNode, self).deserialize(*args, **kw)
except (colander.Invalid,), e:
if e.args[-1] == 'Required':
raise colander.Invalid(self, _('Required input is missing.'))
raise
----- %< -----
I hope at least give you an idea.
On 4/24/12, Anand <[email protected]> wrote:
> Hi,
>
> I am using deform with pyramid. I want to customize the error message for
> validation failures. My schema field looks like
>
> username = colander.SchemaNode(colander.String(), name="username",
> title="Username", oid="login-username",
> widget=TextInputWidget(size=40, css_class="input-xlarge"))
>
> This is a 'require' field. The default validator provided by colander
> throws a Invalid exception with a message 'Required'. I want to customize
> this message and provide more meaningful message. Is there a way to change
> this error message? I could write a custom validator, but the 'required'
> field validation happens before my custom validator is executed. Besides, I
> don't want to write custom validators for every field in my application.
>
> Is there a way to pass in a validation message to colander field
> validations?
>
> Anand
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pylons-discuss/-/uF71jHsbIv0J.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/pylons-discuss?hl=en.
>
>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-discuss?hl=en.