[Zope-dev] How can I find out who visited a URL within my Zope Product?

Toby Dickenson tdickenson@geminidataloggers.com
Wed, 9 Oct 2002 07:41:44 +0100


On Tuesday 08 Oct 2002 10:48 pm, Craeg K Strong wrote:
> Hello:
>
> I would like to log the identity of the authenticated
> user for *every* URL traversal within my Zope Product.
>
> For example, let's say that my forms-based web application contains 50
> screens.  They are all protected such that only authenticated users
> can view them.  Any one of them could be bookmarked, so a user could
> "jump in" at any point.
>
> I want to record the fact that a user visited a screen, each and every
> time they do so.
>
> A natural place to do this would be in a pre-traversal hook, but I seem
> to be stymied by the lack of authentication information in
> __bobo_traverse__ or __before_publishing_traverse__
>
> Can anyone think of a way this could be done?

It cant be done *inside* either of these methods because authentication i=
s not=20
performed until after traversal has been completed. I guess it would be=20
useful for you to have access to other information, such as the response =
code=20
and body length, that are only available once the request has been fully=20
processed.

I have a product which does a similar job. The cleanest implementation I =
could=20
find was use one of the methods you suggest to call the REQUEST._hold met=
hod.=20
This gets the request object to hold on to the object you provide, and de=
lete=20
its reference when the request is finished. Your object can provide a __d=
el__=20
method that performs the real work.

Thats nasty, but it works. I would be interested if you could find anythi=
ng=20
nicer.