On Sep 15, 2007, at 5:10 AM, Леонид Моргун wrote:

I'm using pylons-0.9.6, formencode-0.7.1-r1

I try to validate controller with form:

-----------------------------------------------------
@validate(schema=...,form='register')
def register(self):
        if not hasattr(self,'form_result'):
                return render('/register.myt')
        ... do something with form_result...
        return redirect_to('/redistered_ok')
-----------------------------------------------------

Right, the form should refer to a *different* action that handles rendering the original page.

-----------------------------------------------------
def register(self):
        return render(...

@validate(schame=....,form='register')
def register_validate(self):
        ... do something with form_result ...
        return redirect_to...
-----------------------------------------------------

What do I do wrong? Was this feature broken in new version of pylons?

This is how its supposed to work. If the validation fails, it needs to get the form to display the errors, so it calls the other action and fills them in. Generally, I put a REST dispatch_on decorator on my original function so that POST's go to the other one. So I have code like so:

    @rest.dispatch_on(POST='_handle_login')
    def login(self, skin=None, anonymous=False):
         .....

    @validate(form='login', schema=forms.Login())
    def _handle_login(self):
        .....

And in my lib/base.py I have:
import pylons.decorators.rest as rest

P.S. The first code-block worked with pylons-0.9.5

I'd be amazed if it did, there shouldn't be any way it can render itself since every call to itself will result in the validate being run again, then errors so it calls the action, thus calling validate, etc.

Cheers,
Ben

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to