I was trying to use this decorators like this:
@validate(schema=MySchema(), form='action')
def action(self):
if request.method=='GET':
return render('/form.mako')
else:
return _process_form(self.form_result)
But there are a few problems with this approach:
1. The first time the controller action is called, it renders the
template without removing the special error placement tags.
2. There is no way to set default values for the form other than
coding them into the template. It would be better to be able to set
default values that would be filled only the first time the form is
rendered.
3. There is no way to pass a dynamic state object to the decorator,
that would be passed to the form validators. This is because the
decorator is called at compile time, so the you can only pass to it
static objects as the "state".
4. You actually have to specify the name of the action method that
renders the form as an argument to the decorator, and this method
can't be private (so even if it's not the original action method for
this request, it is callable as an action method directly by itself).
5. The action method will be run every time the form has to be
rendered, e.g. after every failed validation,
so you can't use it to perform initial one-time checks.
All the above problems happen because using the decorator approach to
do too many things using a single method. Trying to work around the
limitations by breaking up the action method into several different
functions also doesn't work well when using this decorator. So it
seems like it's better to do the validation the "long" way, or at
least redesign this decorator to be a class with different methods
that can be overridden.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---