[Zope] acces to file properties on a precondition - WILL SUMMARIZE
Oliver Bleutgen
myzope@gmx.net
Tue, 12 Mar 2002 18:22:22 +0100
Didier Georgieff wrote:
> Hello,
>
> Just trying to test the new (?) policy for writing more how-tos and
> summarized text for the community and see the right (tm) to do it ;-
> )
>
> - I have a subclassed file (with some more properties like
> 'approved')
>
> - I want to use the precondition to check if the file is approved
> before allowing the donwload
>
> - i have a dtml-method for doing it and all is fine __exept__ that the
> context of this script seems to be the container and not the file.
>
> The precondition method aquire the property ('approved') from the
> container (folder) and __not__ from the file.
>
> I tried to use lotta <dtml-with>, some aq_explicit, without luck.
>
>
> I also send a mail from the precondition (with the REQUEST and
> some id/title as informations) for debugging, and it shows that
> __everything__ comes from the container.
>
>
> So, I tried to see where is the problem with an external method
> (stolen from Dieter)
>
> def baseHasAttr(object,attrname):
> obj= getattr(object,aq_base,object)
> return hasattr(obj,attrname)
>
> and calling <dtml-if "baseHasAttr(this(),'approved')>
>>from the precondition script.
>
> and this test shouts : __false__ even if there __is__ an 'approved'
> property on the file object.
>
>
> So i'm lost, and can't figure why i can't access the object instead of
> the container in the precondition.
>
> Is it because of a wrong syntax ?
> Did i missed some aquisition trick ?
> Do this fails because it's derived from file ?
Didier, I might be wrong, but looking at OFS.Image (Zope 2.3.3) I see
if self.precondition and hasattr(self,self.precondition):
# Grab whatever precondition was defined and then
# execute it. The precondition will raise an exception
# if something violates its terms.
c=getattr(self,self.precondition)
if hasattr(c,'isDocTemp') and c.isDocTemp:
c(REQUEST['PARENTS'][1],REQUEST)
else:
c()
i.e. c (your precondition script) gets passed REQUEST['PARENTS'][1] as
the "client" argument. That should explain why your precondition sees
the parent of your file-like object.
Put it also get's passed REQUEST, so perhaps
file_obj = context.REQUEST['PARENTS'][0] should give the file-object itself?
cheers,
oliver