[Zope-dev] z3c.form SequenceWIdget extract
Hi, I am using z3c.form, which is complicated but a lot more flexible than the old zope.formlib. Thanks for building it. Currently, I am having a problem with the SequenceWidget. Let me illustrate the scenario: I have a search-form with batching of the results - the links for the pages of the search contain the search parameters and the action-key as GET-parameters like this search.html?form.widgets.text=fooform.buttons.search=1. With normal Widgets, this works perfectly well. But when my search-form contains a SequenceWidget, this approach breaks, because SequenceWidget depends on zope-functionality in some other place, which transforms paramters with a key-postfix of :list to a list of values (the postfix is appended to the parameter-name by the template). The part of my application, that builds the query-string for the batch does however not have any knowledge about the widget-type of the parameters (that's intentionally to limit the dependencies to the form implementation). This problem would not exist, if the extract-method of SequenceWidget would contain two additional lines of code: def extract(self, default=interfaces.NOVALUE): See z3c.form.interfaces.IWidget. if (self.name not in self.request and self.name+'-empty-marker' in self.request): return [] value = self.request.get(self.name, default) if value != default: if not isinstance(value, (list, tuple)): value = [value] for token in value: if token == self.noValueToken: continue try: self.terms.getTermByToken(token) except LookupError: return default return value I (hope I) can work around this problem by subclassing SequenceWidget and overwrite the extract method, but I wonder, if this fix introduces some unknown problems and whether it can be included in the standard implementation. Thanks, Mat -- Dipl. Inf. Matthias Lehmann Software- und Web-Development Käthe-Kollwitz-Straße 6 99734 Nordhausen fon: +49 3631 470652 mobil: +49 170 5176774 eMail: [EMAIL PROTECTED] web: http://www.matlehmann.de ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
AW: [Zope-dev] z3c.form SequenceWIdget extract
Hi Mat Betreff: [Zope-dev] z3c.form SequenceWIdget extract Hi, I am using z3c.form, which is complicated but a lot more flexible than the old zope.formlib. Thanks for building it. Currently, I am having a problem with the SequenceWidget. Let me illustrate the scenario: I have a search-form with batching of the results - the links for the pages of the search contain the search parameters and the action-key as GET-parameters like this search.html?form.widgets.text=fooform.buttons.search=1. With normal Widgets, this works perfectly well. But when my search-form contains a SequenceWidget, this approach breaks, because SequenceWidget depends on zope-functionality in some other place, which transforms paramters with a key-postfix of :list to a list of values (the postfix is appended to the parameter-name by the template). Can you give a smaple ot the search string which you are using if it contains a sequence widget? I guess this string is wrong and this ends in none sequence data at the server side. If I'm right, now you are trying to convert this simple data string into a sequence, right? Try to build a sequence of values as: search.html?text=footext=bar that's the right way to send sequence data and will give you the result: text = ['foo', 'bar'] at the server side. Regards Roger Ineichen The part of my application, that builds the query-string for the batch does however not have any knowledge about the widget-type of the parameters (that's intentionally to limit the dependencies to the form implementation). This problem would not exist, if the extract-method of SequenceWidget would contain two additional lines of code: def extract(self, default=interfaces.NOVALUE): See z3c.form.interfaces.IWidget. if (self.name not in self.request and self.name+'-empty-marker' in self.request): return [] value = self.request.get(self.name, default) if value != default: if not isinstance(value, (list, tuple)): value = [value] for token in value: if token == self.noValueToken: continue try: self.terms.getTermByToken(token) except LookupError: return default return value I (hope I) can work around this problem by subclassing SequenceWidget and overwrite the extract method, but I wonder, if this fix introduces some unknown problems and whether it can be included in the standard implementation. Thanks, Mat -- Dipl. Inf. Matthias Lehmann Software- und Web-Development Käthe-Kollwitz-Straße 6 99734 Nordhausen fon: +49 3631 470652 mobil: +49 170 5176774 eMail: [EMAIL PROTECTED] web: http://www.matlehmann.de ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Re: AW: [Zope-dev] z3c.form SequenceWIdget extract
Roger Ineichen schrieb: Hi Mat Can you give a smaple ot the search string which you are using if it contains a sequence widget? I guess this string is wrong and this ends in none sequence data at the server side. If I'm right, now you are trying to convert this simple data string into a sequence, right? Try to build a sequence of values as: search.html?text=footext=bar that's the right way to send sequence data and will give you the result: text = ['foo', 'bar'] at the server side. Hi Roger, I am sorry, but I was not clear enough with my description: In my search-form, I have a simple single-select-widget (i.e. a dropdown). My problem is not to transmit multiple values for a single widget over a GET-paramter-string - for this, your solution should work. But I want to use the key and value of this dropdown-widget just the same way as for input-widgets: I want to be able to build a query-string like search.html?form.widgets.dropdown=foo and have the SequenceWidget accept this single value. Currently, SequenceWidget depends on the fact, that in the templates for sequence-widgets, the name of the widget gets a postfix of :list (so form.widgets.dropdown is now form.widgets.dropdown:list) and because of that, the value is transformed to a list by zope.publisher.browser.BrowserRequest. But because the method in my application that builds the query-string has no knowledge about the widget-types - it simple has key-value-pairs - it can not append the :list postfix to the paramter name, thus the value is not transformed to a list and SequenceWidget disregards the value altogether. With the two additional lines, SequenceWidget does not assume anymore, that value has already been transformed to a list (a bold assumtion as I think, since it depends on the default templates) and it will accept query-strings of the given form. Regards, Mat ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
AW: AW: [Zope-dev] z3c.form SequenceWIdget extract
Hi Mat Betreff: Re: AW: [Zope-dev] z3c.form SequenceWIdget extract [...] Hi Roger, I am sorry, but I was not clear enough with my description: In my search-form, I have a simple single-select-widget (i.e. a dropdown). My problem is not to transmit multiple values for a single widget over a GET-paramter-string - for this, your solution should work. But I want to use the key and value of this dropdown-widget just the same way as for input-widgets: I want to be able to build a query-string like search.html?form.widgets.dropdown=foo and have the SequenceWidget accept this single value. Currently, SequenceWidget depends on the fact, that in the templates for sequence-widgets, the name of the widget gets a postfix of :list (so form.widgets.dropdown is now form.widgets.dropdown:list) and because of that, the value is transformed to a list by zope.publisher.browser.BrowserRequest. I see But because the method in my application that builds the query-string has no knowledge about the widget-types - it simple has key-value-pairs - it can not append the :list postfix to the paramter name, thus the value is not transformed to a list and SequenceWidget disregards the value altogether. With the two additional lines, SequenceWidget does not assume anymore, that value has already been transformed to a list (a bold assumtion as I think, since it depends on the default templates) and it will accept query-strings of the given form. Ok, I got it, I think you are right. Stephan, any hints? Regards Roger Ineichen Regards, Mat ___ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )