Re: [web2py] "Simple query" suffers nasty case of user error...

2011-11-03 Thread Bruno Rocha
I guess you need .grid (not smartgrid)

   todos = db.todo.complete==False
   grid=SQLFORM.grid(todos)

-- 

Bruno Rocha
[http://rochacbruno.com.br]


Re: [web2py] "Simple query" suffers nasty case of user error...

2011-11-03 Thread Bruno Rocha
On Thu, Nov 3, 2011 at 4:51 AM, Tom Campbell  wrote:

> ...but I'm too much of a noob to get it.
>
> # file models/db_todo.py
> db.define_table('todo',
>Field('summary','string',requires=IS_NOT_EMPTY()),
>Field('priority',requires=IS_IN_SET([1,2,3,4,5])),
>Field('complete','boolean',default=False))
>
> # file views/main/index.html
> {{extend 'layout.html'}}
> Current tasks
> {{=grid}}
>
> # file controllers/main.py
> @auth.requires_login()
> def index():
># Show only remaining tasks
>todos = db(db.todo.complete==False).select()
>grid=SQLFORM.smartgrid(db.todo,todos)
>return dict(grid=grid)
>
> 1. The main/index.html view is meant to show only completed tasks
> (completed==False). It shows all of them.
>

smartgird does not receives a Rows object as second param, it expects a
dict of table:query

grid=SQLFORM.smartgrid(db.todo,{'todo',db.todo.complete==False})



>
> 2. The dropdowns for Priority start with a blank slot, not 1.


pass zero=None to field requires

Field('priority',requires=IS_IN_SET([1,2,3,4,5], zero=None))

-- 

Bruno Rocha
[http://rochacbruno.com.br]


[web2py] "Simple query" suffers nasty case of user error...

2011-11-02 Thread Tom Campbell
...but I'm too much of a noob to get it.

# file models/db_todo.py
db.define_table('todo',
Field('summary','string',requires=IS_NOT_EMPTY()),
Field('priority',requires=IS_IN_SET([1,2,3,4,5])),
Field('complete','boolean',default=False))

# file views/main/index.html
{{extend 'layout.html'}}
Current tasks
{{=grid}}

# file controllers/main.py
@auth.requires_login()
def index():
# Show only remaining tasks
todos = db(db.todo.complete==False).select()
grid=SQLFORM.smartgrid(db.todo,todos)
return dict(grid=grid)

1. The main/index.html view is meant to show only completed tasks
(completed==False). It shows all of them.

2. The dropdowns for Priority start with a blank slot, not 1.