On Thu, Feb 16, 2012 at 7:57 AM, pipoun <[email protected]> wrote:
> I am trying to find a way to mix a bit of the traversal resource building
> and the pylons controllers functions that have mapped parameters. I am also
> using sqlachemy as orm (so no ZODB).
> Basically, I'm looking for a way to avoid as much as possible the manual
> extraction of parameters from the request object (especially
> request.matchdict).
> I've read the two wiki tutorials, looked at pyramid_handlers, akhet,
> pyramid_metatg, the View Mapper hook, and saw also the "View Callables as a
> Class and Dependency Injection" on the list. I have perhaps to many separate
> information, like pyr_handlers/pyr_metatg don't work with traversal;
> traversal "should be" used with zodb, url dispatch "should be" used with
> sqla; the view mapper example uses add_handler and url dispatch, so no
> traversal possible. I understand the traversal mechanism, but I'm not
> comfortable with the resource/context creation (the tutorial uses ZODB, I'm
> using sqla)...
> So, am I missing something? Is is too complicated? Or not following the
> pyramid philosophy? Do I really have to use traversal?
> ( I come from a turbogears2 background, so my mind may be a bit
> unconsciously biased. )
I'm having trouble understanding your question. Are you saying that
you'd rather use traversal completely, and not use URL dipatch? Do you
want an example of using traversal with SQLAlchemy? When you say
"avoid the manual extraction of parameters", do you mean that you
don't want to use URL dispatch, or that you just don't like
request.matchdict for some reason?
You can use traversal with SQLAlchmey. The Kotti project is the best
example of it, and you can study the source but it's complex. I don't
know of a SQLAlchemy-wiki-traversal tutorial, perhaps somebody should
write one. There are two ways to approach traversal with SQLAlchemy.
If you're doing a single level without recursion; e.g., "/page/ABC",
your root would have a "page" key, which would be some object that
queries the Page table and fetches an "ABC" record. That record either
becomes the resource, or you have some kind of resource class and put
the record inside it.
If you're doing multi-level recursion ("/page/A/B/C" or perhaps
"/A/B/C"), you would need a self-referential table; i.e., a table with
a foreign key column pointing to the same table. Then each record can
point to its parent. Kotti is an example of this.
Traversal is most commonly used with an object database because both
of them are naturally recursive. But I'm seeing more and more use of
traversal with SQLAlchemy, so perhaps it will become just as common in
the future?
--
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.