Hello, Thanks for the guidance. I'm actually getting stuck higher up than this. It's the actual question of how to get the data from the form to the relevant browser view object.
Basically, I've defined a form like this: <html metal:use-macro="views/standard_macros/view"> <body> <div metal:fill-slot="body"> <h1>Quick Search</h1> <form name="quicksearch" method="post" action="searchresults.html"> Max rent (£pcm) <input name="max_rent" type="text" size="2"> <input type="submit" name="Submit" value="Submit"> </form> </div> </body> </html> and configured it for .browser like this: <page name="quicksearch.html" for="lettings.interfaces.property_int.IPropertyFolder" class=".propertyfolder.SearchAdverts" permission="zope.Public" template="quicksearch.pt" menu="zmi_views" title="QuickSearch"/> searchresults.html (the action of the form) comes from this bit of zcml in .browser: <page name="searchresults.html" for="lettings.interfaces.property_int.IPropertyFolder" class=".propertyfolder.SearchAdverts" permission="zope.Public" template="searchresults.pt" menu="zmi_views" title="Search Results"/> and its template looks like this: <html metal:use-macro="views/standard_macros/view"> <body> <div metal:fill-slot="body"> <h1>Search Results</h1> <table> <tr> <th>Number</th> <th>Ad Name</th> <th>Property Address</th> <th>Rent</th> </tr> <tr tal:repeat="ad view/getMatchingAdverts"> <td tal:content="repeat/ad/number">#</td> <td tal:content="ad/__name__">Ad Name</td> <td> <div tal:replace="ad/__parent__/housenumber" /> <div tal:replace="ad/__parent__/street" />, <div tal:replace="ad/__parent__/area" /></td> <td> £<div tal:replace="ad/rent" /> per <div tal:replace="ad/rentper" /></td> </tr> </table> </div> </body> </html> The Python looks like this: class SearchAdverts: """Search adverts for matches to criteria""" def getMatchingAdverts(self, max_rent): """Get all matching adverts.""" context=self.context ads= for name, context in context.items(): #iterate over all Properties in the Property Folder for name, context in context.items(): #iterate over all items in the Property if IAdvert.providedBy(context): # We only care about adverts # - don't need to look at any other items that might be in the Property #apply criteria matching checking here #if matchesCriteria(ad, criteria): if context.rent<max_rent: ads.append(context) return ads (This is just dummy code I've been using to check that I can pass the form values over - I intend to switch it to using Catalog once I've got that part working. I have checked that the loops work by dropping the "max_rent" from the def statement, and fixing the if comparisson value to a number and calling searchresults.html directly and it works.) When I hit submit on the quicksearch page I get an error. The Error report says "getMatchingAdverts() takes exactly 2 arguments (1 given)" - so max_rent isn't getting through to the python. Basically, I've not yet had to make ANY forms in Zope, so I simply don't know how to pass the information from them on to the relevant code. Everything I've done thus far has been with auto-generated forms (add_form, edit_form) so I've not needed to use any of my own generated form yet. And looking through Philipp and Stephan's books, the only forms I've spotted there are generated automatically by Zope too (though I may of course have missed something). I'm sure I'm just being really dense here, so a pointer in the right direction would be greatly appreciated. Thanks, Jim --- Jeff Shell <[EMAIL PROTECTED]> wrote: > Create a browser view object with a method that > looks up the catalog > utility and performs the search and returns results > back to the > template. Basically take what you've learned about > writing views that > combine classes and templates, and use code like the > following: > > def search(self, query): > """simple example, query is just a string""" > catalog = zapi.getUtility(ICatalog, > 'catalog', self.context) > return > catalog.searchResults(some_index=query) > > Of course, you could take in more search parameters > from the form and > pass those in as well. > > On 7/24/05, Jim Vine <[EMAIL PROTECTED]> wrote: > > Hi, > > > > Thanks a lot for the pointer. I have upgraded to > Zope > > 3.1b (with only minor difficulty). > > > > I've read the readme for Catalog, and I think I > more > > or less follow how it works. What I didn't pick up > > from the readme, however, was how I would actually > use > > it in an application. How does one go about > generating > > a search form that accepts a few criteria, and has > a > > "submit" button, that would then go off and > fetches > > the results? > > > > Thanks, > > Jim > > > > > > --- Stephan Richter > <[EMAIL PROTECTED]> > > wrote: > > > > > On Saturday 23 July 2005 16:17, Jim Vine wrote: > > > > It seems from the documentation that ZCatalog > is > > > the > > > > prefered way of doing a search in Zope 2, but > that > > > > this isn't implemented in Zope 3. > > > > > > Use Zope 3.1 beta 1; it has indices and a > catalog > > > implementation. > > > > > > Regards, > > > Stephan > > > -- > > > Stephan Richter > > > CBU Physics & Chemistry (B.S.) / Tufts Physics > > > (Ph.D. student) > > > Web2k - Web Software Design, Development and > > > Training > > > > > > > > > > > > > > > > > > ___________________________________________________________ > > Yahoo! Messenger - NEW crystal clear PC to PC > calling worldwide with voicemail > http://uk.messenger.yahoo.com > > _______________________________________________ > > Zope3-users mailing list > > Zope3firstname.lastname@example.org > > http://mail.zope.org/mailman/listinfo/zope3-users > > > ___________________________________________________________ How much free photo storage do you get? Store your holiday snaps for FREE with Yahoo! Photos http://uk.photos.yahoo.com _______________________________________________ Zope3-users mailing list Zope3email@example.com http://mail.zope.org/mailman/listinfo/zope3-users