A lot of things to comment on.

On Thu, Jan 7, 2010 at 10:35 PM, Chris <[email protected]> wrote:
> I think a lot of folks have ended up writing their own @validate
> decorator to suit their needs (I have as well).  I think there is a
> new one scheduled for 1.0.

It's been postponed till after 1.0 because otherwise it would hold up
the release significantly.

http://pylonshq.com/project/pylonshq/ticket/405

"milestone  changed from 0.10 to 1.0.1

"Right, so I think changing @validate pre-1.0 will screw up too much.
I think a cleaner idiom alltogether is needed, since validation
requires so many options we're weighed down with a massive @validate
with a dozen keyword options that's just horrid.

"@validate should be deprecated post-1.0 when a cleaner way to utilize
FormEncode? in a controller is completed."

The new approach may or may not involve a decorator.  I suspect not,
because an action can't inject 'state' into a decorator.

> I've moved away from htmlfill in favor of a technique Mike Bayer
> blogged about here: http://techspot.zzzeek.org/?p=28
> I use Bayer's formtags.mako in place of htmlfill, but my @validate is
> quite different.  I really like this formtag.mako approach though.

I do something partway.  I use def-with-content to layout a field,
but with no preprocessor and just using ModelTags or the tag helpers:

# Function
## *********** FORM FIELD *******************
<%def name="field(name, label, required=False)">
<div class="field-row">
<label for="${name}">${label} \
% if required:
<span class="required">*</span> \
% endif   required
</label>
<blockquote class="widget">
<form:error name="${name}" />
${caller.body()}
% if hasattr(caller, "hint"):
<div class="hint">${caller.hint()}</div>
% endif   hint
</blockquote>
</div>
</%def>

# Usage
## 'first_name' field
<%call expr="field('first_name', 'First Name', True)">
${mt.text("first_name", size=60, maxlength=60)}
</%call>


# Result
<div class="field-row">
<label for="first_name">First Name <span class="required">*</span> </label>
<blockquote class="widget">
<input id="first_name" maxlength="60" name="first_name" size="60"
type="text" value="Mike" />
</blockquote>
</div>

I have to call htmlfill both for display and validation because of the
<form:error> tag. I either do that manually after rendering, or put
the whole form-generation into a utility method called by both
actions.

I'm not sure if an enhanced render() is feasable for Pylons because
render is supposed to be a simple function that interfaces with a
template system and can be reimplemented for other template systems.
But maybe a wrapper class would work:

from pylons.templating import render_mako
from pylons.somewhere import FormEncodeRenderWrapper
render = FormEncodeRenderWrapper(render_mako)

Then the wrapper could concern itself with forms and validation,
leaving the renderer intact.  Anyway, if you have concrete ideas you
can make a Pylons ticket for them, or put an article in the Pylons
Cookbook and give us a link to it.  That way maybe users could use it
before Pylons incorporates it.

>> On Jan 7, 2:50 pm, "Mike Burrows (asplake)" <[email protected]>
>> > I appreciate that Pylons isn't 1.0 yet but it concerns me a bit that
>> > this stuff doesn't work out of the box; makes one wonder that it's not
>> > used much.

It's just a large task and the developers haven't had time to improve
it.  It works in most cases, so it hasn't been a critical problem.  It
just has limitations and an annoying API.






-- 
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.


Reply via email to