Re: [Zope3-Users] Using zope.formlib for a search form
Thanks for that, Hermann. Yes, it looks like I should have gone straight to z3c.form instead :-) Oh well, a good learning exercise. Cheers, Andrew. Hermann Himmelbauer wrote: Am Freitag, 10. August 2007 04:14 schrieb Andrew Groom: Hi All, I've been battling with formlib for the last three days now and, while Uh oh, sorry, "formlib". My example was based on z3c.form. Anyway, I would recommend you to have a decent look at this library, as I struggled a lot with formlib beforehand (due to very similar problems) and am much more content with z3c.form as it is much more flexible and adaptable. z3c.form is very nicely documented and there are various demos (z3c.formlib), however, it also takes quite some time to get into it. (At least for me). Best Regards, Hermann -- --- Reurbanise - Urban Sustainability ph: (03) 3528 055, mobile: 0274 992 569 http://www.reurbanise.co.nz ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Using zope.formlib for a search form
Am Freitag, 10. August 2007 04:14 schrieb Andrew Groom: > Hi All, > > I've been battling with formlib for the last three days now and, while Uh oh, sorry, "formlib". My example was based on z3c.form. Anyway, I would recommend you to have a decent look at this library, as I struggled a lot with formlib beforehand (due to very similar problems) and am much more content with z3c.form as it is much more flexible and adaptable. z3c.form is very nicely documented and there are various demos (z3c.formlib), however, it also takes quite some time to get into it. (At least for me). Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Using zope.formlib for a search form
Am Freitag, 10. August 2007 04:14 schrieb Andrew Groom: > Hi All, > > I've been battling with formlib for the last three days now and, while > I've learnt a lot, it's nearly driven me crazy. I'm trying to use it to > create simple search form, i.e., a form that does input validation, > remembers the values you entered, etc., but is not tied to a persisted > object. > > I've got the form rendering and processing requests, but I'm completely > stuck on getting the form to remember the values I just entered after a > form post. > > Has anyone got any suggestions ? Here's what I've got so far, the latest > attempt being to use a dummy object to provide the context, which also > doesn't seem to work: Yes, I do the same and use a self-made class, called "ActionForm" for that, it's quite simple: class ActionForm(Formframe, form.Form): """ Generic form for context-less patterns """ def updateWidgets(self): self.widgets = getMultiAdapter( (self, self.request, self.getContent()), IWidgets) self.widgets.ignoreContext = True self.widgets.update() Then I have a persisten object, that acts as an entry point to my view, and which may provide various methods, e.g.: class SearchData(persistent.Persistent): implements(ISearchData) def search_data(self, **kd): # Here the data is retrieved, in my case from a relational database return data And then there's the view: class ViewSerachKunde(ActionForm): formErrorsMessage = _('There were some errors.') template = ViewPageTemplateFile('pt/searchdata.pt') fields = field.Fields(IViewSearchData) # If data is found, it's stored in a view-object-attribute found_data = None @button.buttonAndHandler('Search', name='search') data, errors = self.extractData() if errors: self.status = self.formErrorsMessage return self.found_data = self.context.search_data(**data) And then in my template file I have something like this (please note that I use a custom library for displaying fields (formsnippet): <--! This displayes the search-widgets --> <--! And this displays the found data --> Found Data: Best Regards, Hermann -- [EMAIL PROTECTED] GPG key ID: 299893C7 (on keyservers) FP: 0124 2584 8809 EF2A DBF9 4902 64B4 D16B 2998 93C7 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] Using zope.formlib for a search form
On Thursday 09 August 2007 22:14, Andrew Groom wrote: > I've been battling with formlib for the last three days now and, while > I've learnt a lot, it's nearly driven me crazy. I'm trying to use it to > create simple search form, i.e., a form that does input validation, > remembers the values you entered, etc., but is not tied to a persisted > object. > > I've got the form rendering and processing requests, but I'm completely > stuck on getting the form to remember the values I just entered after a > form post. > > Has anyone got any suggestions ? Here's what I've got so far, the latest > attempt being to use a dummy object to provide the context, which also > doesn't seem to work: Unfortunately, I cannot help you here, since I have been using z3c.form recently (of course). z3c.form is better documented and provides the hooks I think you are looking for here. For example, the context for the form -- called content within z3c.form -- can be overwritten by implementing a custom ``getContent()`` method. If you do that, you can store your info in a session for example. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users