[Zope] Access rule for Python Product

Paul Winkler pw_lists@slinkp.com
Tue, 15 Apr 2003 22:07:58 -0700


On Tue, Apr 15, 2003 at 08:06:22PM -0700, Chad Nantais wrote:
> I need to run a function whenever my python product is published.  This 
> function will record the name os the user that viewed the object and the 
> id of the object.
> 
> If I was doing this all through the ZMI, I would create an access rule 
> for each customer (folderish) object instance.  However, I want this 
> access rule built into my product.  How would I do this?

build it in to the view method of your class.
Something like this (untested, and assuming you use zlog for the records) ...

from zLOG import LOG
from AccessControl import getSecurityManager

class MyProduct(some_zopeish_base_class):
    ...
    index_html = None   # tell the publisher to use __call__ for the view
    def __call__(self, client=None, REQUEST=None, RESPONSE=None, **kw)
        user = getSecurityManager().getUser()
        LOG('User %s viewed %s' % (user, self.getId())
        ...
    
           
-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's RANDY PROCTOLOGIST!
(random hero from isometric.spaceninja.com)