Please open a ticket about this and link this thread. they should work the same. I never had a problem with it but we will take a second look.
On Monday, 11 February 2013 12:32:05 UTC-6, 黄祥 wrote: > > hi anthony, > > thank for your explaination, but i'm sorry, i'm still not understand. i've > already tried to learn from trial and error like the code that i've shown > above. the unexpected result above, is mean that i can not view the page > that is authorize to me (as an *admin membership*). the strange behaviour > on my second post is when i submit the data in form, it won't work. > my goal is to set the function that can be used by another function. let > say __grid_0() can be used by manage_blog() and manage_news() for example > > here is the code that i'm tried : > *#model* > db.define_table('blog', > Field('title'), > Field('contents', 'text'), > format='%(title)s') > > #controller work for a moment > # pagination function > def __pagination_0(flash, table, active): > response.flash=T(flash) > if len(request.args): > page=int(request.args[0]) > else: > page=0 > items_per_page=10 > limitby=(page*items_per_page, (page+1)*items_per_page+1) > rows=db(active==True).select(limitby=limitby, orderby=~table.id, > cache=(cache.ram, 10)) > return dict(rows=rows, page=page, items_per_page=items_per_page) > > # grid function > @auth.requires(auth.has_membership(role = 'Admin')) > def __grid_0(flash, table): > response.flash=T(flash) > has_membership=auth.has_membership('Admin') > grid=SQLFORM.smartgrid(table, user_signature=False, > onupdate=auth.archive, > create=has_membership, editable=has_membership, > deletable=has_membership) > return dict(grid=grid) > > blog_flash="Blog" > blog_db=db.blog > blog_active=db.blog.is_active > blog_manage_flash="Manage Blog" > > # blog > def blog(): > return __pagination_0(blog_flash, blog_db, blog_active) > > # manage_blog > def manage_blog(): > return __grid_0(blog_manage_flash, blog_db) > > *#view* > *blog.html* > {{extend 'layout.html'}} > > {{for i,row in enumerate(rows):}} > {{if i==items_per_page: break}} > {{=DIV(H2(row.title))}} > {{=DIV(row.contents)}} > {{=prettydate(row.created_on)}} > {{=BR()}} > {{pass}} > > {{if page:}} > {{=SPAN(A(T('< Previous'), _href=URL(args=[page-1]), _title=T('Previous > Page')))}} > {{pass}} > > {{if len(rows) > items_per_page:}} > {{=SPAN(A(T('Next >'), _href=URL(args=[page+1]), _title=T('Next Page')))}} > {{pass}} > > *manage_blog.html* > {{extend 'layout.html'}} > > {{=grid}} > > On Monday, February 11, 2013 9:49:29 PM UTC+7, Anthony wrote: >> >> These should be equivalent, though technically >> @auth.requires_membership('Admin') is equivalent to @auth.requires(lambda: >> auth.has_membership(role='Admin')). Using the lambda prevents >> unnecessary database hits checking for membership in cases where the >> controller file is executed but the specific decorated function is not >> called. >> >> Perhaps you can post a minimal app that reproduces the problem. >> >> Anthony >> >> On Sunday, February 10, 2013 11:40:45 PM UTC-5, 黄祥 wrote: >>> >>> hi, >>> >>> what is the difference within : >>> @auth.requires_membership('Admin') and >>> @auth.requires(auth.has_membership(role = 'Admin')) >>> it seems there is some limitation in @auth.requires_membership('Admin') >>> >>> e.g. >>> *case 1 :* >>> *as expected result* >>> *@auth.requires(auth.has_membership(role = 'Admin')) ### the difference* >>> def __grid_0(flash, table): >>> response.flash=T(flash) >>> has_membership=auth.has_membership('Admin') >>> grid=SQLFORM.smartgrid(table, onupdate=auth.archive, >>> create=has_membership, >>> editable=has_membership, >>> deletable=has_membership) >>> return dict(grid=grid) >>> >>> def manage_blog(): >>> return __grid_0(blog_manage_flash, blog_db) >>> >>> *unexpected result* >>> *@auth.requires_membership('Admin') ### the difference* >>> def __grid_0(flash, table): >>> response.flash=T(flash) >>> has_membership=auth.has_membership('Admin') >>> grid=SQLFORM.smartgrid(table, onupdate=auth.archive, >>> create=has_membership, >>> editable=has_membership, >>> deletable=has_membership) >>> return dict(grid=grid) >>> >>> def manage_blog(): >>> return __grid_0(blog_manage_flash, blog_db) >>> >>> what i mean for unexpected result is, the user with the membership of >>> group 'Admin' can not see the manage_blog page, when i modified it with >>> *@auth.requires(auth.has_membership(role = 'Admin'))*, the user with >>> the membership of group 'Admin' can see the manage_blog page. >>> >>> is there anyone know about it? >>> >>> thank you so much in advance >>> >> -- --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.