Searching a FieldIndex by ZPT
Hi Zopers 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 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> <input type="hidden" name="year_of_birth_index.range:record" value="minmax"> <tr><td colspan=2 align=center> <input type="SUBMIT" value="Submit Query"> </td></tr> </table> </form> Another detail: when I get results in the report form via "results here/Catalog" and put them in a batch, how do I get the total length of the results? It is a LazyCat and __len__() does not seem to work. thanks kind regards Andre
--On Sonntag, 14. März 2004 17:29 Uhr +0100 Andre Meyer <a.meyer@hccnet.nl> wrote: Using
request = {'year_of_birth_index':{'query':[1000, 1500],
is very much different from using this:
<td><input name="year_of_birth_index.query:record" width=30 value="1000, 1500"></td></tr>
I suggest to put your this query somewhere in a python script and call the script instead of moving to much complicated logic inside the ZPT. -aj
Andre Meyer wrote:
Another detail: when I get results in the report form via "results here/Catalog" and put them in a batch, how do I get the total length of the results? It is a LazyCat and __len__() does not seem to work.
results/sequence_length if my memory serves me correctly... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
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
participants (4)
-
Andre Meyer -
Andreas Jung -
Chris Withers -
Dieter Maurer