[Grok-dev] megrok.traject

Martijn Faassen faassen at startifact.com
Thu Dec 3 07:04:46 EST 2009


Hi there,

Christian Klinger wrote:

> i currently play a bit with megrok.traject. Does anyone
> knew how i locate the user object in the factory?

I'm not sure what your goal is. Do you mean you want to give User a 
__parent__ and a __name__ within the factory already? Could you explain 
why? It will be given a location automatically as soon as it leaves the 
factory. locate is only useful on objects that you retrieve elsewhere 
(and you want to get their URL or do a security check).

> class SomeTraject(traject.Traject):
>       grok.context(Pgrestraject)

This looks odd. What's Pgrestraject? The context of a traject shouldn't 
be another traject, it should be some model (such as your application).

>       pattern = 'users/:user_id'
>       model = User
> 
>       def factory(self, user_id):
>           session = Session()
>           user = session.query(User).filter(
>                     User.id == int(user_id)).one()
>           return user
> 
>       def arguments(user):
>           return dic(user_id=user.id)
> 
> I tried it with megrok.traject.locate but this needs an root
> object. I don't know how i can get the root object.

If it's your application, you could use getSite() or (getApplication 
once it's there).

Regards,

Martijn



More information about the Grok-dev mailing list