On Sun, Mar 23, 2008 at 1:57 PM, Wichert Akkerman <[EMAIL PROTECTED]> wrote:
> validate does lots of things: > > - it extract parameters from a request according to a defined schema > - it validates the decoded data > - it optionally redirect the request elsewhere if validation fails > - it transform the response to insert form values and error messages > > At the moment you get all four in one decorator. If you want a subset of > them you have to code the whole thing yourself. I'm not sure what the > best way to make that more modular - we don't want to make the common > case more complex for developers. Yes, that's the dilemma. @vaidate tries to do several different things, so it works only in one specific form scenario. Anybody who wants only part of it has to reimplement it in their controllers, which they're reluctant to do because @validate is part of Pylons so it must be the right way, and that little decorator looks so elegant and clean. Pylons should be able to do better than this, but what? At minimum it can add boolean arguments to disable its features piecemeal. But that doesn't help somebody who needs to do validation *inside* their action, perhaps to get a database record to validate against, or check if the user is authorized to do what they're doing. (Not all authorization can be done in a decorator or in .__before__.) Perhaps we need some validation function or class, or a group of functions, that can be called both in the action and in the decorator. That way the decorator will seem more like an optional extra rather than the only place where the validation code is neatly bundled together. By the way, when I brought up to Ben the fact that sometimes you need to validate against a database record, but you don't know *which* record until the action begins, unless you parse the URL id both in the action and in the validator -- he said Routes assigns all routing variables as 'c' attributes, so the validator can pick up the id from there. But then again, the validator has to call into the model to get the record, and that may or may not violate MVC. (Should the validator be calling the model?) This could be avoided by moving away from @validate completely and providing some smaller functions or a class the user can call in the action. -- Mike Orr <[EMAIL PROTECTED]> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
