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: > It is failing when items=[] > replace > > {{=SQLTABLE(items,headers="fieldname:capitalize")}} > > with > > {{=SQLTABLE(items,headers="fieldname:capitalize") if items else > "nothing to see here"}} > > On Sep 15, 5:12 pm, elfuego1 <elfue...@gmail.com> wrote: > > > 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() > > if not items: response.flash="There are no matching records in > > Database." > > else: items=[] > > return dict(form=form,items=items) > > > On 15 Wrz, 23:08, mdipierro <mdipie...@cs.depaul.edu> wrote: > > > > 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 <elfue...@gmail.com> 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 <mdipie...@cs.depaul.edu> 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 <elfue...@gmail.com> 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 <mdipie...@cs.depaul.edu> 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 <elfue...@gmail.com> 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 <mdipie...@cs.depaul.edu> 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 <elfue...@gmail.com> 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 <mdipie...@cs.depaul.edu> 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 <elfue...@gmail.com> 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 <mdipie...@cs.depaul.edu> > > > > > > > > > > > > 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 > > ... > > więcej »