[Zope] allow access to fileobject depending on role
Jonathan
dev101 at magma.ca
Thu Jun 1 08:01:25 EDT 2006
----- Original Message -----
From: "leandros van den berg" <l.vandenberg at geo.uu.nl>
To: <chris at simplistix.co.uk>
Cc: <zope at zope.org>
Sent: Thursday, June 01, 2006 4:49 AM
Subject: Re: Re: [Zope] allow access to fileobject depending on role
> > Chris Withers wrote:
>>> I'm having trouble with the precondition field of a fileobject. I've got
>>> a fileobject (a PDF-file) and its precondition field states
>>> myPrecondition, which is a DTML Method and its code is:
>
>> This is insane...
>
> Why is this insane? Because of using a precondition, the code of the
> method or the hole idea?
>
>>> Note: Using the security setting and assigning roles is not an option
>>> because the fileobject is recreated every night.
>>
>>
>> Rubbish. Two options:
>>
>> - don't recreate the file each night, just edit its contents.
>
> I'm thinking of manage_upload or update_data to edit the file content, but
> I can't figure out how to apply them. Hell, I can't even figure out how to
> select the file that is to be updated!
> I use the following two objects for replacing the existing file.
>
> 1. External Method 'printbestand'
>
> def printbestand():
> filename='/home/leandros/myzope/instance/Extensions/printbestand.pdf'
> f=open(filename)
> filebody=f.read()
> f.close
> return filebody
>
> if __name__ == "__main__":
> print printbestand()
>
> 2. Script (Python) 'printbestand_upload':
>
> try:
> context.manage_delObjects(ids='printbestand.pdf')
> except:
> pass
> fileobject = context.printbestand()
> context.manage_addFile('printbestand.pdf',file=fileobject,
> content_type='application/pdf')
> return 0
>
> As you can see in 'printbestand_upload', the file is deleted first and
> then the new file is added. Obviously the existing file should not be
> deleted but its content updatad/edited/replaced.
>
> My question are:
> Q1: How do I select the file that is to be updated?
> Q2: How do I update the content of that file with the content of the new
> file?
>
Try something like:
fileObj = context.restrictedTraverse('/folderA/folderB/printsbestand.pdf')
fileData = context.printsbestand()
fileObj.update_data(fileData, content_type='application/pdf',
size=len(fileData) )
Warning: untested!
Look in the ZopeBook for more info.
hth
Jonathan
More information about the Zope
mailing list