http://web2py.com/books/default/chapter/29/09#Authorization
auth.has_membership(group_id, user_id, role)
checks whether user_id has membership of the group group_id or the group
with the specified role. Only group_id or role should be passed to the
function, not both. If the user_id is not specified, then web2py assumes
the current logged-in user.
so, you're switching parameters.... it's auth.has_membership('Tutors') or
auth.has_membership('Tutors', auth.user_id), not the other way around.
BTW: remember to set those defaults (ones that are retrieved by a query) in
a lazy_table environment, else the query to retrieve if the user has the
membership will happen on every request. Alternatively you can set the
default only when it's needed, e.g. in your controller:
def testfunction():
db.table.field.default = auth.has_membership('Tutors')
On Saturday, December 8, 2012 7:40:21 PM UTC+1, Daniele wrote:
>
> I want to tick a checkbox if a user has membership to something, else
> leave unticked.
> I tried putting it in the Field's default variable as such,
> Field('is_tutor', 'boolean', default=auth.has_membership(auth.user_id,
> 'Tutors')) but this is causing an error. What's the correct way to do this?
>
> Thanks
>
--