[Zope] Searching a FieldIndex by ZPT

Dieter Maurer dieter at handshake.de
Mon Mar 15 13:57:36 EST 2004


Andre Meyer wrote at 2004-3-14 17:29 +0100:
>So, I finally managed to search a FieldIndex in my Catalog in Python 
>like this:
>
>            request = {'year_of_birth_index':{'query':[1000, 1500], 
>'range': 'minmax'}}
>            obj = self.Catalog.search(request)
>
>            print obj.__len__(), 'objects found'
>            for i in range(obj.__len__()):
>                print i , obj.__getitem__(i).title, 
>obj.__getitem__(i).getObject().year_of_birth

Uhh! Are you trying to obfuscate your code?

The following looks much clearer. Do you not agree?

    result = self.Catalog(year_of_birth_index =
                          {'query':[1000,1500], 'range':'min:max'}
			  ):
    print len(result), 'objects found'
    for i in range(len(result)):
	proxy = result[i]
        print i, proxy.title, proxy.getObject().year_of_birth
         

>Now I want to do the exact same thing in ZPT, but get no results, why?
>
>        <form action="index_report" method="get">
>            <table>
>                <tr><th>Search Year of Birth</th>
>                    <td><input name="year_of_birth_index.query:record" 
>width=30 value="1000, 1500"></td></tr>

This will give you a string but you need a list.
This means that your action must convert the string into a list
probably by splitting at ",", stripping and converting to "int".


-- 
Dieter



More information about the Zope mailing list