[Zope] Another Formulator tweak (SingleItemsWidget)

Jean Jordaan jean at upfrontsystems.co.za
Thu Sep 4 16:35:20 EDT 2003


Hi Martijn

I propose changing this in Widget.SingleItemsWidget::

     def render_items(self, field, key, value, REQUEST):

         # get items
         items = field.get_value('items')

         # check if we want to select first item
         if not value and field.get_value('first_item') and len(items) > 0:
             try:
                 text, value = items[0]
             except ValueError:
                 value = items[0]

to this::

     def render_items(self, field, key, value, REQUEST):

         # get items
         items = field.get_value('items')

         # check if we want to select first item
         if not value and field.get_value('first_item') and len(items) > 0:
             text, value = _splitItem(items[0])
         elif not isinstance(value, StringType):
             try:
                 value = value[0] # Are we some kind of sequence?
             except TypeError:
                 pass # Lets just hope value is the same type as items ..

The changes are:

  - use `_splitItem(items[0])` to avoid breaking when `items[0]`
    happens to be a 2-char string

  - catering for when value is ['thing'] instead of just 'thing'
    (the `not isinstance(value, StringType)` clause).

I'm a bit unsure about the details of the 2nd change. Can value
legitimately be a list (i.e. can items be a list of lists?)

(This isn't a patch because we're too far out of sync with cvs
  HEAD :/ )

Regards,
-- 
Jean Jordaan
http://www.upfrontsystems.co.za




More information about the Zope mailing list