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
[Zope3-Users] Using zope.formlib for a search form
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: #-- # Classes for bulding the search form #-- class UserSearchForm (Form): # Vocab for boolean items bool_vocab = SimpleVocabulary.fromItems([('Any', ''), ('Yes', 'true'), ('No', 'false')]) # Form fields form_fields = Fields(Choice( __name__='is_verified', vocabulary=bool_vocab, title=u"Is verified?", description=u"Has the users email address been verified ?"), Choice( __name__='is_opted_in', vocabulary=bool_vocab, title=u"Has opted in for emails", description=u"Has the user opted in for emails ?"), Choice( __name__='is_old_extension_user', vocabulary=bool_vocab, title=u"Is not using the latest extension", description=u"Is the user using the latest extension ?"), Choice( __name__='is_extension_user', vocabulary=bool_vocab, title=u"Is an extension user", description=u"Is the user using the extension ?"), ) # Vocab for email templates templates = EmailTemplates() template_vocab = SimpleVocabulary.fromItems(templates.get_tuples()) form_fields += Fields(Choice( __name__='template', vocabulary=template_vocab, title=u"Email template?", readonly=True, description=u"Choose an email template ?" ), ) prefix = 'search' label = 'Search for Users' template = ViewPageTemplateFile('templates/searchform.pt') actions = form.Actions( form.Action('search', success='process_search'), form.Action('process', success='process_action'), ) _results = None #-- # Dummy search form context object #-- class UserSearchFormData: def __init__ (self): self.is_old_extension_user = True self.is_extension_user = False self.is_verified = True self.is_opted_in = False #-- # Classes for registering the search form as a content provider #-- class UserSearchFormProvider: implements(IContentProvider) adapts(Interface, IDefaultBrowserLayer, Interface) def __init__(self, context, request, view): self.context = context self.request = request self.__parent__ = view self.obj = UserSearchFormData() self.form = UserSearchForm(self.obj, self.request) def update(self): pass def render(self): import pdb; pdb.set_trace() return self.form() #-- # User admin view #-- class UserAdminView (BrowserView): def __init__ (self, context, request): self.context = context self.request = request # Set up the form content provider provideAdapter(UserSearchFormProvider, name="vortexuser.UserSearchFormProvider") Many thanks for any help. Cheers, Andrew. --- 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