You get an error in response.write(SQLTABLE(items,headers="fieldname:capitalize"))
that seems to indicate items is not the result of a select but a list. What is items? On Sep 15, 3:57 pm, elfuego1 <[email protected]> wrote: > That doesn't work as planned. > > First scenario. > I added the code you provided above and got error: > > Error traceback > > Traceback (most recent call last): > File "gluon/restricted.py", line 188, in restricted > File "F:\Programy\web2py\applications\myapp/views\default/ > search.html", line 92, in <module> > File "gluon/sqlhtml.py", line 1192, in __init__ > AttributeError: 'list' object has no attribute 'colnames' > > Line 92: > response.write(SQLTABLE(items,headers="fieldname:capitalize")) > > This error shows when I'm on index.html page and I want to go to > search.html > > Second scenario. > I didn't add > {{=SQLTABLE(items,headers="fieldname:capitalize")}} > to search.html page yet. I go from index.html to search.html page > first. Search page shows up with all my old code in it. I make the > change you suggested and only refresh the search.html and there I can > see the alias column names I wanted. > BUT I can't get there from index.html any more. I can see the changed > page only if I'm refreshing search page but not if I want to get there > from index.html page. The change in code blocks me somehow from going > there. > Can you tell me why? How to remove the error? > > Best regards. > > But when I'm on search.html page and add the line you gave me > Strange thing with link redirecting me to my search.html page. > When I'm on search.html > > On 14 Wrz, 13:28, mdipierro <[email protected]> wrote: > > > yes in search.html > > > remove this: > > > {{try:}}{{=H2(message)}}{{except:}}{{=BEAUTIFY(response._vars)}} > > {{pass}} > > > Add this: > > > {{=SQLTABLE(items,headers="fieldname:capitalize")}} > > > On Sep 13, 10:41 pm, elfuego1 <[email protected]> wrote: > > > > Where do you suggest I should add it? In search.html ? > > > > {{try:}}{{=H2(message)}}{{except:}}{{=BEAUTIFY(response._vars)}} > > > {{pass}} > > > {{=SQLTABLE(items,headers={'numbers.no_1':'No 1'})}} > > > > Then I get two rows of columns: > > > > items : > > > numbers.id numbers.no_1 numbers.no_2 numbers.no_3 > > > numbers.no_4 > > > numbers.no_5 numbers.no_6 numbers.date > > > numbers.id No 1 numbers.no_2 No 2 numbers.no_3 No 3 > > > numbers.no_4 No 4 numbers.no_5 No 5 numbers.no_6 No 6 > > > numbers.date > > > > Can you show me where should I add it? > > > > On 13 Wrz, 21:16, mdipierro <[email protected]> wrote: > > > > > You mean in items. That depends on how you display them. Perhaps one > > > > of these: > > > > > {{=SQLTABLE(items,headers={'numbers.no_1':'No1'})}} > > > > > or > > > > > {{=SQLTABLE(items,headers='fieldname:capitalize'}}} > > > > > On Sep 13, 12:56 pm, elfuego1 <[email protected]> wrote: > > > > > > I have desired aliases in form fields names but in result set I > > > > > receive: > > > > > > items: numbers.id numbers.no_1 numbers.no_2 numbers.no_3 > > > > > numbers.no_4 numbers.date > > > > > > I'd like to change column names in result > > > > > from: numbers.no_1 > > > > > into: No 1 > > > > > > I also noticed that the values from the form are not checked in > > > > > Database. In DB I have a record: > > > > > no_1 = 1 > > > > > no_2 = 3 > > > > > no_3 = 13 > > > > > no_4 = 16 > > > > > > But when I enter values 1,3,13,21 into the form fields and submit data > > > > > I always get: "There are no matching records in Database." > > > > > The result should show 3 matching recors. > > > > > > It looks like the values are not checked against DB at all... > > > > > > <Storage {'no_4': 21, 'no_1': 1, 'no_2': 3, 'no_3': 13, 'id': 1}> > > > > > > On 13 Wrz, 04:11, mdipierro <[email protected]> wrote: > > > > > > > There is no colnames > > > > > > > form=SQLFORM.factory(Field('no_1','integer'), > > > > > > Field('no_2','integer',label="Alias name for col2"), > > > > > > Field('no_3','integer'), > > > > > > Field('no_4','integer')) > > > > > > > On Sep 12, 8:51 pm, elfuego1 <[email protected]> wrote: > > > > > > > > I'd like to use some aliasing for column names yet. > > > > > > > When I added this in search function: > > > > > > > > items.colnames=['no_1','no_2','no_3','no_4'] > > > > > > > > if form.accepts(request.vars,keepvalues=True): > > > > > > > items=db(db.lotto_generated.no_1.contains(form.vars.no_1)|\ > > > > > > > db.lotto_generated.no_2.contains(form.vars.no_2)|\ > > > > > > > db.lotto_generated.no_3.contains(form.vars.no_3)|\ > > > > > > > > > > > > > > db.lotto_generated.no_4.contains(form.vars.no_4)).select() > > > > > > > > items.colnames=['no_1','no_2','no_3','no_4'] > > > > > > > <= HERE > > > > > > > else: items=[] > > > > > > > return dict(form=form,items=items) > > > > > > > > Then I've got a ticket: > > > > > > > > AttributeError: 'list' object has no attribute 'colnames' > > > > > > > > So how can I change my column names in result part of the form? > > > > > > > > On 12 Wrz, 02:05, mdipierro <[email protected]> wrote: > > > > > > > > > My bad. Not > > > > > > > > > form=SQLFORM.factory(INPUT('no_1','integer'), <= line 57 > > > > > > > > INPUT('no_2','integer'), > > > > > > > > INPUT('no_3','integer'), > > > > > > > > INPUT('no_4','integer')) > > > > > > > > > but > > > > > > > > > form=SQLFORM.factory(Field('no_1','integer'), <= line 57 > > > > > > > > Field('no_2','integer'), > > > > > > > > Field('no_3','integer'), > > > > > > > > Field('no_4','integer')) > > > > > > > > > On Sep 11, 6:32 pm, elfuego1 <[email protected]> wrote: > > > > > > > > > > In index.html I've added link to redirect to search.html > > > > > > > > > page.: > > > > > > > > > > {{=P(A(T("Click to search the Database"), > > > > > > > > > _href=URL('myapp','default','search')),_style="padding-top:1em;")}} > > > > > > > > > > When I try to go to search page I get this error: > > > > > > > > > > Error traceback > > > > > > > > > > Traceback (most recent call last): > > > > > > > > > File "gluon/restricted.py", line 186, in restricted > > > > > > > > > File > > > > > > > > > "F:/Programy/web2py/applications/myapp/controllers/default.py", > > > > > > > > > line 69, in <module> > > > > > > > > > File "gluon/globals.py", line 96, in <lambda> > > > > > > > > > File > > > > > > > > > "F:/Programy/web2py/applications/myapp/controllers/default.py", > > > > > > > > > line 57, in search > > > > > > > > > File "gluon/html.py", line 358, in __init__ > > > > > > > > > SyntaxError: <input/> tags cannot have components > > > > > > > > > > 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) > > > > > > > > > > response._vars=response._caller(search) <= line > > > > > > > > > 69 > > > > > > > > > > On 11 Wrz, 22:16, mdipierro <[email protected]> wrote: > > > > > > > > > > > I would do this: > > > > > > > > > > > db.define_table('numbers', > > > > > > > > > > Field('nos', 'list:integer', widget=ListStringWidget), > > > > > > > > > > Field('date', 'date',default=now) > > > > > > > > > > > where StringListWidget is defined > > > > > > > > > > here:http://groups.google.com/group/web2py/msg/0c2600730ece873a > > > > > > > > > > then > > > > > > > > > > > def search(): > > > > > > > > > > form=SQLFORM.factory(INPUT('no1','integer'), > > > > > > > > > > INPUT('no2','integer'), > > > > > > > > > > INPUT('no3','integer'), > > > > > > > > > > INPUT('no4','integer')) > > > > > > > > > > if form.accepts(request.vars,keepvalues=True)): > > > > > > > > > > items=db(db.numbers.nos.contains(form.vars.no1)|\ > > > > > > > > > > db.numbers.nos.contains(form.vars.no2)|\ > > > > > > > > > > db.numbers.nos.contains(form.vars.no3)|\ > > > > > > > > > > db.numbers.nos.contains(form.vars.no4)).select() > > > > > > > > > > else: items=[] > > > > > > > > > > return dict(form=form,items=items) > > > > > > > > > > > On Sep 11, 1:05 pm, elfuego1 <[email protected]> wrote: > > > > > > > > > > > > Here are some more detailed informations you asked for: > > > > > > > > > > > > The form has to search always for 4 numbers. > > > > > > > > > > > The result may show 4 numbers or less (when matched). > > > > > > > > > > > Position is not important. > > > > > > > > > > > Search will be always for 4 numbers. > > > > > > > > > > > All 4 fields have numbers. There are no empty fields in > > > > > > > > > > > DB. > > > > > > > > > > > > On 11 Wrz, 16:19, mdipierro <[email protected]> > > > > > > > > > > > wrote: > > > > > > > > > > > > > Will your search form accept one number or 4? Do you > > > > > > > > > > > > need to search > > > > > > > > > > > > for records that have any of the numbers of all of the > > > > > > > > > > > > numbers? Are > > > > > > > > > > > > the position (1,2,3,4) and the numbers important? Is 4 > > > > > > > > > > > > fixed or may > > > > > > > > > > > > that increase in the future? Can the value of any of > > > > > > > > > > > > the no_x fields > > > > > > > > > > > > be None or other than a number? > > > > > > > > > > > > > On Sep 11, 12:12 am, elfuego1 <[email protected]> > > > > > > > > > > > > wrote: > > > > > > > > > > > > > > Hello, > > > > > > > > > > > > > > I need to create a search form. > > > > > > > > > > > > > In my DB I have fields with numbers. Now I need to > > > > > > > > > > > > > look up the DB and > > > > > > > > > > > > > find out if the numbers I enter are there already or > > > > > > > > > > > > > not. > > > > > > > > > > > > > > db.define_table('numbers', > > > > > > > > > > > > > Field('no_1', > > ... > > read more »

