Mike Bayer (of Mako and SQLAlchemy) posted this:

http://techspot.zzzeek.org/2008/07/01/better-form-generation-with-mako-and-pylons/

While it discusses Pylons, it does address one possible method without
using a form library (or, using Mako as a form library). The method
isn't limited to Mako, you could do it with Jinja2 or any other
reasonably powerful templating language.

I like deform - it has some very sophisticated widgets that make
developing some rather complex forms easy. The only issue I have
(coming from an SQLAlchemy background and not a zodb background) is
that it requires some magic to bring appstruct over to an object that
SQLAlchemy can use.

http://cd34.com/blog/framework/using-pyramid-with-deform-to-editcreate-records-in-sqlalchemy-backed-database/

WTForms is very Djangolike and works pretty well. We used it as the
form library for Apex. Formalchemy's documentation is in a state of
flux. They swapped maintainers moved the site, some of the links 404.
If you are looking for a form library that is very well tied to your
SQLAlchemy model schemas and has a RESTful interface, it works pretty
well.

If you're just looking to use webhelpers in your existing forms, you
would add it to your subscribers:

something like:

project/lib/subscribers.py:

from pyramid.threadlocal import get_current_request
from project.lib import helpers

def add_renderer_globals(event):
    request = event.get('request')
    if request is None:
        request = get_current_request()
    globs = {
        'h':helpers,
        }
    event.update(globs)

project/lib/helpers.py:

from webhelpers.text import plural
from webhelpers.date import distance_of_time_in_words
from webhelpers.date import time_ago_in_words

project/__init__.py:

 
config.add_subscriber('project.lib.subscribers.add_renderer_globals',
                          'pyramid.events.BeforeRender')

In your template (Jinja example, Mako would use ${ } rather than
{{ }}:

        <br /><span id="p-{{data.id}}">{{h.plural(data.points,
'point', 'points')}}</span> by <a href="/user/
{{data.author.username}}">{{data.author.username}}</a>
{{h.distance_of_time_in_words(data.posted_date, granularity='hour')}}
ago | <a href="/news/{{data.id}}/
{{data.slug}}">{{h.plural(data.comment_count, 'Comment', 'Comments')}}
</a>

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