AW: [Zope-dev] z3c.form SequenceWIdget extract

Roger Ineichen dev at projekt01.ch
Sat Mar 15 00:07:20 EDT 2008


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=foo&form.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=foo&text=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: info at matlehmann.de
> web:   http://www.matlehmann.de



More information about the Zope-Dev mailing list