On Thu, Feb 11, 2010 at 9:54 AM, Mike Burrows <[email protected]> wrote:
>
> Personally, I would be happy to see a decorator-free Pylons but I say
> that without knowing what our action methods will look like without
> them!
You can do it now; the trouble is you either have to work up from a
minimal try/except or work down from the @validate code. The problem
with the @validate code is it's hard to separate the universal pattern
from the specific argument slinging the decorator does.
The pattern is something like this (untested):
'''
try:
val = MyValidator()
data = val.to_python(request.params, None)
except formencode.Invalid, e:
html = self.form_method()
html = htmlfill.render(html, request.params,
e.unpack_errors(), force_defaults=False)
return html
# Success, perform action using ``data``.
'''
The render args are the source HTML, input values, and errors.
``e.unpack_errors()`` converts the error dict from a nested structure
(if applicable) to the flat HTML format. ``force_defaults=False``
prevents htmlfill from unsetting radio buttons and selects.
I would read the source code for render (formencode/htmlfill.py) and
Invalid (formencode/api.py) to get a feel for what exactly it's doing
and the possible arguments.
--
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.