[Zope] accessing custom properties of file objects

Jesse Goerz jgoerz@cfl.rr.com
21 Jun 2002 04:13:15 -0400

On Fri, 2002-06-21 at 00:10, Jesse Goerz wrote:
> On Thu, 2002-06-20 at 15:40, Dieter Maurer wrote:
> > Hmm, you do not tell us, it what way the other code does not work...
> > 
> >   exception? (which one, with Error Type/Value and tracebach)
> >   wrong result?
> >   something else?
> Sorry about that.  I posted prematurely.  I seem to be able to test if
> the property I created is there but I'd really like to base my
> conditions on the value of the property.  Below is my amended code as
> well as the tracebacks.
> <table border="1" width="95%" bgcolor="#000000" cellspacing="2"
> cellpadding="2" align="center"  
>    tal:define="objects here/files;
>    sort_on python:(('id', 'nocase', 'asc'),
>    ('bobobase_modification_time', 'cmp', 'desc'));
>    sorted_objects python:sequence.sort(objects, sort_on)">
>  <tbody>
>     <tr>
>      <th>Filename</th>
>      <th>Size</th>
>      <th>Description</th>
>      <th>Last modified</th>
>   </tr>
>   <tr tal:repeat="item sorted_objects">
> <!-- 
> This one displays all the file objects with a property of "section", but
> I want to display based on the value of "section", i.e. there will be
> multiple different sections throughout the html page, each in its own
> table.
> <div tal:condition="python:exists('item/section')"
> -->
> <div tal:condition="python:'item/section'=='c'"
>      tal:omit-tag>
>      <td>
>       <a href="http://jesse.homelinux.net/sample"
>          tal:attributes="href item/getId" 
>          tal:content="item/getId">File_link</a>
>      </td>
>      <td tal:content="item/file_size">Type</td>
>      <td tal:content="item/title">Description</td>
>      <td tal:content="item/date_mod" align="center">Last modified</td>
> </div>
>   </tr>
>  </tbody>  
> </table>
> The statement I'm working on here is:
> <div tal:condition="python:'item/section'=='c'" tal:omit-tag>
> That above gives no errors but outputs only one blank row.

I was having a hard time with the expressions so I tried a python script
instead which seems to work.  Here's what I did:
returns all 'File' objects with property 'section' set to 'c'
all_files = context.objectValues('File')
c_files = []
for i in all_files:
      if getattr(i, 'section') == 'c':
return c_files

What is the exact syntax of the sort method?  I was trying to sort like I did above:
>    sort_on python:(('id', 'nocase', 'asc'),
>    ('bobobase_modification_time', 'cmp', 'desc'));
>    sorted_objects python:sequence.sort(objects, sort_on)">

The docs state that sequence.sort(seq, sort_schema) where sort schema is
a tuple (key, function, direction).  I used the exact same values ('id',
'nocase', 'asc') and I get 
Error Type: TALESError
Error Value: exceptions.AttributeError on 'None' object has no attribute
'getitem' in "standard:'here/c_section'", at line 22, column 1