[Zope3-Users] How to access "request" variable from vocabulary

Hermann Himmelbauer dusty at qwer.tk
Tue Aug 7 04:33:19 EDT 2007


Am Montag, 6. August 2007 19:08 schrieb Benji York:
> Adam Groszer wrote:
> > I'm using something like this:
> >
> > def getCurrentRequest():
> >     return getInteraction().participations[0]
>
> It is, of course, better if you can structure your app so you don't have
> to pull the request "out of thin air", but if you do, I'd be a little
> more careful about it.  Like so:
>
> def getRequest():
>      i = zope.security.management.getInteraction() # raises
> NoInteraction
>      for p in i.participations:
>          if IRequest.providedBy(p):
>              return p
>      raise RuntimeError('Could not find current request.')

Ah, thanks a lot for this, it works.

In my RDB/SQLAlchemy-based application, when a user logs in, his 
database-userID is stored into the session. In some forms, I have choices 
which are filled with user-related data (e.g. his email addresses). To 
retrieve this data from the relational database, I need the ID from the 
session.

I'd prefer if the vocabulary had direct access to the request, but it seems 
that vocabularies are bound to the content object and not to the view, 
whereas the request is only available in the view.

One solution could be to build a view-bound vocabulary, but that's probably 
hard to do and may break other things.  So this seems like a structural 
problem that is not easy to solve.

Best Regards,
Hermann

-- 
x1 at aon.at
GPG key ID: 299893C7 (on keyservers)
FP: 0124 2584 8809 EF2A DBF9  4902 64B4 D16B 2998 93C7


More information about the Zope3-users mailing list