options=[str(my_macaddr[i].MacAddr) for i in range(len(my_macaddr))]
form=SQLFORM.factory(Field('macs',requires=IS_IN_SET(options,multiple='multiple')))
dbset=db4((db4.data_table.ReqTime>='2010-11-08T21:00')&(db4.data_table.ReqTime<='2010-11-08T22:00'))
if form.accepts(request) and form.vars.macs:
query = reduce(lambda a,b:a|b,[db4.data_table.MacAddr==x for x in
form.vars.macs])
dbset=dbset(query)
records =
dbset.select(db4.data_table.MacAddr,db4.data_table.ReqTime,db4.data_table.Po)
On Nov 12, 10:02 am, Lorin Rivers <[email protected]> wrote:
> Sorry I wasn't clear.
>
> I'm using a select multiple element in my form. When more than one (in my
> example, it's a MAC address) item is chosen, I need to return a result set
> for each choice and display them together.
>
> I could do it with a query like: "choice 1 OR choice 2" or I could do it by
> combining the results of separate queries without the OR (there's also a date
> range but that's from a separate field and is hard-coded while I figure this
> other bit out).
>
> I'm having trouble constructing the code to handle the multiple selections.
> The form returns the request.vars just fine, so that part of my code is
> working. I think I need to loop through the request.vars in my controller to
> build my query or queries but I can't figure out how. I tried using a loop
> from i to len(request.vars) but that didn't work.
>
> On Nov 11, 2010, at 21:01, mdipierro <[email protected]> wrote:
>
> > sorry I do not understand the question.
>
> > On Nov 11, 6:12 pm, Lorin Rivers <[email protected]> wrote:
> >> I have a form using this:
> >> options=[str(my_macaddr[i].MacAddr) for i in range(len(my_macaddr))]
> >>
> >> form=FORM(SELECT(*options,_name='MacAddrSelect',_multiple='multiple'),INPUT
> >> (_type='submit'))
>
> >> records = db4((db4.data_table.MacAddr==request.vars.MacAddrSelect) &
> >> (db4.data_table.ReqTime>='2010-11-08T21:00') &
> >> (db4.data_table.ReqTime<='2010-11-08T22:00')).select(db4.data_table.MacAddr,db4.data_table.ReqTime,db4.data_table.Po)
>
> >> How do I create a loop that will return records using more than one
> >> selection in my form?
> >> --
> >> Lorin Rivers
> >> Mosasaur: Killer Technical Marketing <http://www.mosasaur.com>
> >> <mailto:[email protected]>
> >> 512/203.3198 (m)
>
>