[Grok-dev] spotlight on: megrok.traject
faassen at startifact.com
Fri Jan 15 08:30:46 EST 2010
megrok.traject is a package that allows a different way to publish your
models than the traversal that is most commonly used in Zope
applications. With megrok.traject you can define explicitly what kind of
URLs you want to publish your models on, instead of having to construct
an object hierarchy.
A model can be anything that you want to have views for, and doesn't
need to be a persistent ``grok.Model``. In fact megrok.traject is most
suitable for objects that are not stored in the ZODB, as the ZODB makes
What kind of models could you publish with megrok.traject then? It
could be just Python objects you design yourself. In this case you can
use ``traject.Model``. You tell it under what URL pattern it should
appear and how it is to be constructed, and you're done.
``traject.Model`` is very lightweight: it's just a ``grok.Context`` that
can be hooked up by a "traject pattern".
Alternatively you may want to treat your models even more lightly: you
may wish to hook up models that are defined by a package that is not
under your control at all. You could have for instance an ORM such as
SQAlchemy define the models in an entirely different package that knows
nothing about how these models should be presented on the web in your
application. You can then use ``traject.Traject`` to associate such
models with a URL pattern in your application.
You can look at the megrok.traject documentation for more information:
The low-level implementation is a reusable library called ``traject``,
and its documentation can give you more details:
If you still don't understand why megrok.traject would be useful for
*you*, don't worry. Grok's traversal method of publishing objects isn't
going anywhere, and megrok.traject is just an option. If you have
questions, we'd very much like to hear them on grok-dev however, so that
we can improve megrok.traject and its documentation.
Volunteers who would want to write a tutorial oriented towards beginners
that uses megrok.traject would also be very welcome!
More information about the Grok-dev