SQLFORM.smartgrid and constraint

665 views
Skip to first unread message

vivek

unread,
Nov 20, 2012, 10:06:15 AM11/20/12
to web...@googlegroups.com
Hi ,

     I been using SQLFORM.smartgrid and constraint successfully in many places. But for some reason my constraint for this particular grid isnt working

def approval():
    response
.title=" Quotes waiting approval "
    response
.view = 'Final/quotes/qapproval.html'
    q_comm
= db.quote.status == "Approval"
    constraints
= {'db.quote':q_comm}
    form
= SQLFORM.smartgrid(db.quote,constraints = constraints, linked_tables=['quoteitem'],deletable=dict(quote=False,quotelines=True), editable=dict(quote=True,quotelines=True), details=dict(quote=False,quotelines=False),create=dict(quote=False,quotelines=True),links = dict(quote=[lambda row: A(SPAN(_class='icol-accept'),_href=URL("quote","convert",args=[row.id]))]),csv=False)
   
return dict(form=form)




I have a common filter in my model


if auth.is_logged_in():
   
if not auth.has_membership('admin'):
        db
.quote._common_filter = lambda query: (db.quote.accmanager ==  auth.user_id) | (auth.user_id == 10) | (auth.user_id == 5)


Thanking all
Vivek




Jim S

unread,
Nov 20, 2012, 12:46:10 PM11/20/12
to web...@googlegroups.com
Try changing:

constraints = {'db.quote':q_comm}

to:

constraints = {'quote':q_comm}

Does that help?

-Jim

vivek

unread,
Nov 20, 2012, 1:10:03 PM11/20/12
to web...@googlegroups.com
Nope that doesn't help.

vivek

unread,
Nov 20, 2012, 1:34:27 PM11/20/12
to web...@googlegroups.com
No I am wrong it works! 

Thank you so much!

Jim Steil

unread,
Nov 20, 2012, 3:21:38 PM11/20/12
to web...@googlegroups.com

Glad to hear.

--
 
 
 

Sairam Kolla

unread,
May 4, 2015, 11:56:36 AM5/4/15
to web...@googlegroups.com
Hi

I have a table called posts which have title,id,body,auth.signature as their Fields.In a view called 'Posts' i want to display a grid of all the posts made by that particular user.So in the controller i have written like this


def view():
    constraints
={'created_by':auth.user_id}
    grid
=SQLFORM.smartgrid(db.posts,constraints=constraints)
    return locals()

But the grid contains all the posts and there are no filtered.Can anyone help me out please....

黄祥

unread,
May 4, 2015, 12:15:16 PM5/4/15
to web...@googlegroups.com
e.g.
def view():
    constraints = db.posts.created_by == auth.user_id
    grid=SQLFORM.smartgrid(db.posts, constraints = constraints)
    return locals()
   
ref:
https://groups.google.com/forum/#!topic/web2py/mtbhY19aAEA

best regards,
stifan

Sairam Kolla

unread,
May 10, 2015, 10:01:57 AM5/10/15
to web...@googlegroups.com
it works!. Thankyou.I have another question.What if there are multiple queries.What is the syntax?

eg: query1= db.posts.created_by==auth.user_id
query2=db.posts.gender=='male' (assume there is a field called gender)


--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/cNMqkf9hmKo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

黄祥

unread,
May 10, 2015, 4:12:35 PM5/10/15
to web...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages