getSecurityManager.getUser() in __getitem__ Was: [Zope] Method with Dot in the name
Thomas Guettler
Thomas Guettler <thomas@thomas-guettler.de>
Sun, 24 Nov 2002 14:00:34 +0100
On Sat, Nov 23, 2002 at 09:07:32PM +0100, Dieter Maurer wrote:
> Thomas Guettler writes:
> > Up to now I server some files in my Python Product with
> > a URL like .../download?file=foo.doc.
> >
> > It would be much better if the URL would be .../foo.doc
> >
> > Does someone know how this could be done?
> >
> > The files are from the filesystem of the server. They are not in the
> > ZODB.
> You give your product a "__getitem__(self,key)" method.
> It is called by ZPublisher when an attribute lookup failed,
> "key" will be the next URL segment, "foo.doc" in your example.
Thank you for this hint!
It works 95%. Since no REQUEST is given to __getitem__ I get
it like this:
if hasattr(self, 'REQUEST'):
request=self.REQUEST
This or something differnt seems to change the result
of getSecurityManager().getUser(): I always get the
anonymous user.
Does someone know why getUser() in __getitem__ is diffent than in
other methods?
The next thing is working, but it is not nice: the call to
__getitem__() returns the content of a file to the browser. But Zope
misses the docstring of the string. I solved by adding the content to
the request object and returning a function which returns this, but a
nicer solution would be better:
request._return_file=self.download(key, REQUEST=request)
def return_wrapper_with_docstring(REQUEST):
"docstring"
return REQUEST._return_file
return return_wrapper_with_docstring
--
Thomas Guettler <guettli@thomas-guettler.de>
http://www.thomas-guettler.de