[Zope] ZPT get_size question

David Pratt fairwinds at eastlink.ca
Wed Feb 9 15:28:51 EST 2005


Hi.  I have a list of objects from a folder that I obtained using 
objectValues and then batched. I wrote a short script to format the 
results of size so I get nice kB, MB, etc. My ZPT to deal with this 
formating looks like this:

...tal:define="file_size item/size" 
tal:content="python:here.getFileSize(file_size)">##.# kB</td>

This works fine for getting data from using objectValues.

Now, I am modifying my CMF folder_contents template. CMF 
folder_contents pulls its content together using items python: 
here.listFolderContents(contentFilter=filter)
I am batching on item.

First off, I can't get size using item/size without an attribute error 
as follows:

     *  Module Products.PageTemplates.Expressions, line 198, in __call__
     * Module Products.PageTemplates.Expressions, line 201, in __call__
     * Module Products.PageTemplates.Expressions, line 189, in _eval
     * Module Products.PageTemplates.Expressions, line 145, in _eval
     * Module Products.PageTemplates.Expressions, line 354, in 
restrictedTraverse

AttributeError: size

  but I can get the size information using item/get_size.  Now if I 
attempt to gather item/get_size in a variable like this:

...tal:define="file_size item/get_size" 
tal:content="python:here.getFileSize(file_size)">##.# kB</td>

  it throws the following key error:

     *  Module Products.PageTemplates.TALES, line 221, in evaluate
     * Module Products.PageTemplates.Expressions, line 198, in __call__
     * Module Products.PageTemplates.Expressions, line 201, in __call__
     * Module Products.PageTemplates.Expressions, line 189, in _eval
     * Module Products.PageTemplates.Expressions, line 145, in _eval
     * Module Products.PageTemplates.Expressions, line 347, in 
restrictedTraverse
     * Module OFS.ObjectManager, line 663, in __getitem__

KeyError: 'get_size'

My function in not causing any trouble.  If I replace the tal:content 
section with tal:content="file_size", I will get the same error. So two 
questions:

1) Why I can't put the data in a variable in the same way I had done 
previously?
2) Is there another way I can get the size of the object here.  Why 
doesn't item/size return the size in this case? Am I not still dealing 
with a list of objects from the folder?

I should say that I am using a condition on the items since there are 
folders and files in a folder.  So if it is a folder it will return a 
structure statement to put a &nbsp; in my table. So I am only trying to 
get the size on items other than folders. The full line looks like this:

<span tal:condition="not: folderish" tal:define="file_size 
item/get_size" tal:omit-tag="" tal:content="file_size">##.# kB</span>

Regards,
David


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2751 bytes
Desc: not available
Url : http://mail.zope.org/pipermail/zope/attachments/20050209/21c623db/attachment.bin


More information about the Zope mailing list