Thanks for the response - at least I know I was not missing any
feature of the current framework.

Aah - makes sense now that | is being used in the context of an OR
operator, and not just a delimiter!

For reference, here is a version of get_fruit_list from my previous
example that is compatible with gae:

def get_fruit_list(fruit_ids):
    stripped_list =  fruit_ids.lstrip('|').rstrip('|')
    if stripped_list=='':
        return "No fruit"
    id_list = stripped_list.split('|')
    fruit = db().select(db.fruit.ALL);
    return ', '.join([row.name for row in fruit.find(lambda row:
str(row.id) in id_list)])

On Mar 22, 1:02 am, mdipierro <[email protected]> wrote:
> This mechanism is one of the worst things in web2py. There should be a
> list type that maps into ListProperty on GAE and something like this
> on RDMS but hides what you suggest.
>
> Anyway |1|2|11| allows you to search for |1| or |2| or |11|.
>
> This 1|2|11 would create problems when searhing for 1, in
> particularing considering that values can be non-numeric.
>
> On Mar 21, 5:48 pm, what_ho <[email protected]> wrote:
>
>
>
> > As an example of amultipleselect field definition:
>
> > db.define_table('fruit',Field('name'))
> > db.define_table('fruit_basket',Field('contents'))
> > db.fruit_basket.contents.requires=IS_IN_DB(db,'fruit.id','%
> > (name)s',multiple=True)
>
> > db.fruit.insert('apple')
> > db.fruit.insert('orange')
> > db.fruit.insert('banana')
>
> > When I subsequently edit one fruit_basket record with crud, I get a
> >multipleselect drop-down of all the available fruit. So far so good.
>
> > When this record is subsequently displayed, the fruit_basket contents
> > field gets output as a list of ids like |1|2|3|  .I actually want a
> > list of fruit to appear.
>
> > This is how I managed it using the represents property of a field:
>
> > db.define_table('fruit_basket',Field('contents',
> >                                 'text',
> >                                 represent=lambda fruit_ids: 
> > get_fruit_list(fruit_ids)))
>
> > def get_fruit_list(fruit_ids):
> >     stripped_list =  fruit_ids.lstrip('|').rstrip('|')
> >     if stripped_list=='':
> >         return "No fruit"
> >     return ', '.join([row.name for row in
> > db(db.fruit.id.belongs(stripped_list.split('|'))).select()])
>
> > This works, but it seems wrong that I'm manually parsing the text
> > field. Anyone aware of a more elegant way to do this? (like calling
> > into a pre-existing web2py function to get back the ids as a list?)
>
> > IS_IN_DB(...,multiple=True) is a validator used by SQLFORM / crud.
> > Another way of stating my question is if I directly access amultiple
> > value field, how can I best access and manipulate this field the same
> > way that the validator code would?
>
> > Also just out of curiosity, anyone know why amultipleselect field
> > starts and ends with a | so values are like |1|2|3| instead of 1|2|
> > 3 ?
>
> > Thanks

-- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en.

Reply via email to