My controller is calling _to_python on a schema object:
@validate(schema=UserCreateValidation(), form='new',
post_only=True)
def create(self):
# controller code here...
Inside the schema is where I call the validator:
class UserCreateValidation(formencode.Schema):
password = formencode.All(FlexPassword())
# more schema code here...
I can't call `FlexPassword#_to_python` because `value` and `state`
aren't known by the schema.
The `UserCreateValidation` schema includes other validations, so I
know the controller is calling it even when the password field is
blank. What's happening though, is the schema seems to ignore
`password = formencode.All(FlexPassword())` when the password is
blank.
Do I need to add an additional argument to `formencode#All` to make
sure it runs `FlexPassword` even when the value is blank?
On Aug 13, 5:49 pm, Eric Rasmussen <[email protected]> wrote:
> Hi Ryan,
>
> In your example below, _to_python always works for me if I call it directly
> (as a method of the class). Is there any chance that your controller isn't
> calling it when the value is an empty string? It might help to see how your
> controller is referencing it.
>
> Best,
> Eric
>
>
>
> On Fri, Aug 13, 2010 at 7:46 AM, Ryan <[email protected]> wrote:
> > I have a custom validator called `FlexPassword`
>
> > class FlexPassword(formencode.FancyValidator):
> > def _to_python(self, value, state):
> > raise formencode.Invalid('validator ran', value, state)
>
> > Here's my schema:
>
> > password =
> > formencode.All(formencode.validators.PlainText(not_empty=True),
> > FlexPassword())
>
> > As expected, when no characters are entered, the PlainText error is
> > raised. Also as expected, when a single character is entered, the
> > FlexPassword error is raised.
>
> > But that's not the schema I want to use. This is:
>
> > password = formencode.All(FlexPassword())
>
> > Contrary to expectation, when no characters are entered, the
> > FlexPassword error is not raised. Huh? As expected, when a single
> > character is entered, the FlexPassword error is raised.
>
> > The way I've got it wired up, the form should always fail validation,
> > but with a blank password, it passes. Any insights for me? Thanks.
>
> > --
> > 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]<pylons-discuss%2bunsubscr...@go
> > oglegroups.com>
> > .
> > 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.