replace

        s=[int(form.vars['no_%i'%i]) for i in keys if form.vars['no_
%i'%i]!=None]
        query=reduce(lambda a,b:a|b,[db.numbers['no_%i'%i].belongs(s)
for i in keys])

with

        query=reduce(lambda a,b:a&b,[db.numbers['no_
%i'%i]==form.vars['no_%i'%i])
for i in keys])

On Sep 21, 8:35 pm, elfuego1 <elfue...@gmail.com> wrote:
> Thank you Massimo!!!
>
> It works on my end as well! ;-)
>
> Could you yet tell me how to modify query part, if I'd like to have
> results shown ONLY, if the numbers are in exactly the same order as
> they are stored in DB?
>
> no_1 == db.numbers['no_1'] &
> no_2 == db.numbers['no_2'] &
> no_3 == db.numbers['no_3'] &
> no_4 == db.numbers['no_4']
>
> Is there a way to display matching values or fields with matching
> values in different color?
> For example: red
>
> On 21 Wrz, 17:11, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > Model:
>
> > db.define_table('numbers',
> >                 Field('no_1', 'integer',
> > requires=IS_INT_IN_RANGE(0,10000)),
> >                 Field('no_2', 'integer',
> > requires=IS_INT_IN_RANGE(0,10000)),
> >                 Field('no_3', 'integer',
> > requires=IS_INT_IN_RANGE(0,10000)),
> >                 Field('no_4', 'integer',
> > requires=IS_INT_IN_RANGE(0,10000)),
> >                 Field('date', 'date'))
>
> > Controller:
>
> > def search():
> >     form=SQLFORM.factory(
> >       Field('no_1','integer',label="No 1"),
> >       Field('no_2','integer',label="No 2"),
> >       Field('no_3','integer',label="No 3"),
> >       Field('no_4','integer',label="No 4"))
> >     if form.accepts(request.vars,keepvalues=True):
> >         keys=(1,2,3,4)
> >         s=[int(form.vars['no_%i'%i]) for i in keys if form.vars['no_
> > %i'%i]!=None]
> >         query=reduce(lambda a,b:a|b,[db.numbers['no_%i'%i].belongs(s)
> > for i in keys])
> >         items=db(query).select()
> >         if not items: response.flash="There are no matching records in
> > Database."
> >     else:
> >         items=[]
> >     return dict(form=form,items=items)
>
> > View: default/search.html
>
> > {{extend 'layout.html'}}
> > {{=form}}
> > {{=SQLTABLE(items,headers="fieldname:capitalize") if items else
> > "Nothing to see here."}}
>
> > This works for me.
>
> > On Sep 21, 9:21 am, elfuego1 <elfue...@gmail.com> wrote:
>
> > > Hello,
>
> > > Did you manage to find a cause of the problem?
> > > Why the db search is not working?
>
> > > Best wishes,
>
> > > On 19 Wrz, 18:26, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > My office email server appears to be done. Maintenance perhaps.
>
> > > > On Sep 19, 11:13 am, elfuego1 <elfue...@gmail.com> wrote:
>
> > > > > Ok. I've sent it again.
> > > > > Should be there right now.
>
> > > > > On 19 Wrz, 16:42, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > > nope
>
> > > > > > On Sep 19, 4:52 am, elfuego1 <elfue...@gmail.com> wrote:
>
> > > > > > > Has my message reached your e-mail?
> > > > > > > The email topic: "Simple search form"
>
> > > > > > > On 17 Wrz, 23:37, elfuego1 <elfue...@gmail.com> wrote:
>
> > > > > > > > I did as you suggested.
> > > > > > > > The mail should be in your mail box.
>
> > > > > > > > On 17 Wrz, 15:55, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > > > > > You need to help some bore with debugging. Looks to me there 
> > > > > > > > > simply is
> > > > > > > > > no matching data.
> > > > > > > > > Try search by one single filed, Try print the values of 
> > > > > > > > > form.vars.
>
> > > > > > > > > or send me the app and I will take a look.
>
> > > > > > > > > On Sep 17, 8:47 am, elfuego1 <elfue...@gmail.com> wrote:
>
> > > > > > > > > > OK. Both parts are there in the view.
> > > > > > > > > > The input fields are not evaluated against Database though.
> > > > > > > > > > Even if I enter numbers that are there in DB, form 
> > > > > > > > > > responses with:
> > > > > > > > > > "There are no matching records in Database."
>
> > > > > > > > > > If the numbers are matching they should be displayed in the 
> > > > > > > > > > result
> > > > > > > > > > part of the search page.
>
> > > > > > > > > > I tried something like this aslo:
>
> > > > > > > > > > items=db(db.numbers.no_1==form.vars.no_1|\
> > > > > > > > > >             db.numbers.no_2==form.vars.no_2|\
> > > > > > > > > >             db.numbers.no_3==form.vars.no_3|\
> > > > > > > > > >             db.numbers.no_4==form.vars.no_4).select()
>
> > > > > > > > > > But it's not working either.
>
> > > > > > > > > > Can I count on some hint?
>
> > > > > > > > > > Best wishes.
>
> > > > > > > > > > On 16 Wrz, 23:19, mdipierro <mdipie...@cs.depaul.edu> wrote:
>
> > > > > > > > > > > somewhere you still have in it
>
> > > > > > > > > > > {{=SQLTABLE(items,headers="fieldname:capitalize")}}
>
> > > > > > > > > > > which as we said only works {{if items:}}
>
> > > > > > > > > > > Please remove everything from the view.
> > > > > > > > > > > You should just have
>
> > > > > > > > > > > {{extend 'layout.html'}}
> > > > > > > > > > > {{=form}}
> > > > > > > > > > > {{=SQLTABLE(items,headers="fieldname:capitalize") if 
> > > > > > > > > > > items else
> > > > > > > > > > > "nothing to see here"}}
>
> > > > > > > > > > > On Sep 16, 4:15 pm, elfuego1 <elfue...@gmail.com> wrote:
>
> > > > > > > > > > > > OK. Both parts are there in the view.
>
> > > > > > > > > > > > Now, when I go from index.html to search.html I get an 
> > > > > > > > > > > > error:
>
> > > > > > > > > > > > Traceback (most recent call last):
> > > > > > > > > > > >   File "gluon/restricted.py", line 188, in restricted
> > > > > > > > > > > >   File 
> > > > > > > > > > > > "F:\Programy\web2py\applications\myapp/views\default/
> > > > > > > > > > > > search.html", line 88, in <module>
> > > > > > > > > > > >   File "gluon/sqlhtml.py", line 1192, in __init__
> > > > > > > > > > > > AttributeError: 'list' object has no attribute 
> > > > > > > > > > > > 'colnames'
>
> > > > > > > > > > > > Line 88:
> > > > > > > > > > > > response.write(SQLTABLE(items,headers="fieldname:capitalize"))
>
> > > > > > > > > > > > On 16 Wrz, 22:02, mdipierro <mdipie...@cs.depaul.edu> 
> > > > > > > > > > > > wrote:
>
> > > > > > > > > > > > > You have a form:
>
> > > > > > > > > > > > > def search():
> > > > > > > > > > > > >     form=SQLFORM.factory(INPUT('no_1','integer'),     
> > > > > > > > > > > > > <= line 57
> > > > > > > > > > > > >       INPUT('no_2','integer'),
> > > > > > > > > > > > >       INPUT('no_3','integer'),
> > > > > > > > > > > > >       INPUT('no_4','integer'))
> > > > > > > > > > > > >     if form.accepts(request.vars,keepvalues=True):
> > > > > > > > > > > > >       
> > > > > > > > > > > > > items=db(db.numbers.no_1.contains(form.vars.no_1)|\
> > > > > > > > > > > > >             db.numbers.no_2.contains(form.vars.no_2)|\
> > > > > > > > > > > > >             db.numbers.no_3.contains(form.vars.no_3)|\
> > > > > > > > > > > > >             
> > > > > > > > > > > > > db.numbers.no_4.contains(form.vars.no_4)).select()
> > > > > > > > > > > > >     else: items=[]
> > > > > > > > > > > > >     return dict(form=form,items=items)
>
> > > > > > > > > > > > > you need to but both
>
> > > > > > > > > > > > > {{=form}}
>
> > > > > > > > > > > > > and
>
> > > > > > > > > > > > > {{=SQLTABLE(items,headers="fieldname:capitalize") if 
> > > > > > > > > > > > > items else
> > > > > > > > > > > > > "nothing to see here"}}
>
> > > > > > > > > > > > > in the view
>
> > > > > > > > > > > > > On Sep 16, 2:25 pm, elfuego1 <elfue...@gmail.com> 
> > > > > > > > > > > > > wrote:
>
> > > > > > > > > > > > > > I did as you told me. Now I don't have search form 
> > > > > > > > > > > > > > on my search page.
> > > > > > > > > > > > > > What do you mean by saying: >>it is only producing 
> > > > > > > > > > > > > > "nothing to see
> > > > > > > > > > > > > > here"
> > > > > > > > > > > > > > because there is no data.<<
> > > > > > > > > > > > > > There is data in DB waiting to be searched, but how 
> > > > > > > > > > > > > > am I supposed to
> > > > > > > > > > > > > > do that now when there is no input fields on search 
> > > > > > > > > > > > > > page?!
> > > > > > > > > > > > > > How do I get input fields and results for my search 
> > > > > > > > > > > > > > below?
>
> > > > > > > > > > > > > > This is some vicious circle...
>
> > > > > > > > > > > > > > On 16 Wrz, 02:47, mdipierro 
> > > > > > > > > > > > > > <mdipie...@cs.depaul.edu> wrote:
>
> > > > > > > > > > > > > > > It is working just not being called. The output 
> > > > > > > > > > > > > > > you see comes from
> > > > > > > > > > > > > > > this code you have
>
> > > > > > > > > > > > > > > {try:}}{{=H2(message)}}{{except:}}{{=BEAUTIFY(response._vars)}}
> > > > > > > > > > > > > > > {{pass}}
>
> > > > > > > > > > > > > > > and you should remove it.
>
> > > > > > > > > > > > > > > The code I suggested:
>
> > > > > > > > > > > > > > > {{=SQLTABLE(items,headers="fieldname:capitalize") 
> > > > > > > > > > > > > > > if items else
> > > > > > > > > > > > > > > "nothing to see here"}}
>
> > > > > > > > > > > > > > > is working all right but it is only producing 
> > > > > > > > > > > > > > > "nothing to see here"
> > > > > > > > > > > > > > > because there is no data.
>
> > > > > > > > > > > > > > > On Sep 15, 6:56 pm, elfuego1 <elfue...@gmail.com> 
> > > > > > > > > > > > > > > wrote:
>
> > > > > > > > > > > > > > > > Source code for search.html looks like that:
>
> > > > > > > > > > > > > > > > {{extend 'layout.html'}}
> > > > > > > > > > > > > > > > {{try:}}{{=H2(message)}}{{except:}}{{=BEAUTIFY(response._vars)}}
> > > > > > > > > > > > > > > > {{pass}}
> > > > > > > > > > > > > > > > {{=SQLTABLE(items,headers="fieldname:capitalize")
> > > > > > > > > > > > > > > >  if items else
> > > > > > > > > > > > > > > > "nothing to see here"}}
>
> > > > > > > > > > > > > > > > The output page looks like that:
>
> > > > > > > > > > > > > > > > form    :
> > > > > > > > > > > > > > > > No 1:
> > > > > > > > > > > > > > > > No 2:
> > > > > > > > > > > > > > > > No 3:
> > > > > > > > > > > > > > > > No 4:
>
> > > > > > > > > > > > > > > > items   :
> > > > > > > > > > > > > > > > numbers.id numbers.no_1 numbers.no_2 
> > > > > > > > > > > > > > > > numbers.no_3 numbers.no_4
> > > > > > > > > > > > > > > > nothing to see here
>
> > > > > > > > > > > > > > > > As you can see aliasing is not working at the 
> > > > > > > > > > > > > > > > moment.
> > > > > > > > > > > > > > > > Moreover when I put numbers into fields 
> > > > > > > > > > > > > > > > (numbers that are in database)
> > > > > > > > > > > > > > > > - nothing happens.
> > > > > > > > > > > > > > > > Values are not checked against DB.
> > > > > > > > > > > > > > > > I only get flash message: "There are no 
> > > > > > > > > > > > > > > > matching records in Database",
> > > > > > > > > > > > > > > > although I know that these numbers are in DB...
>
> > > > > > > > > > > > > > > > Something is missing but I can't figure out 
> > > > > > > > > > > > > > > > what it is.
>
> > > > > > > > > > > > > > > > On 16 Wrz, 01:09, mdipierro 
> > > > > > > > > > > > > > > > <mdipie...@cs.depaul.edu> wrote:
>
> ...
>
> read more »

Reply via email to