I would refer you to the Fine Manual, where you will find things like
auth.has_permission, auth.has_membership, @auth.requires_permission(),
@auth.requires_membership()
If those don't do what you want, you can always join tables as Johann
suggested. The join would look like this:
(
(db.auth_user.id==db.auth_membership.user_id) &
(db.auth_membership.group_id==db.auth_group.id) &
# more clauses ...
).select(
# select whatever you want from any of the three tables in the main query
db.auth_group.role
)
Then, assuming you have the auth_user record id, which you might name
"user_id" replace "more clauses" with
(db.auth_user.id==user_id)
If you want to find all the doctors, replace with this:
(db.auth_group.role=='doctor')
Why are you calling on_define to set the requires attributes for the
registration table? Seems like an unnecessary function call when you can do
them in-line on the field def.
On Tuesday, November 5, 2013 1:02:12 AM UTC-5, 黄祥 wrote:
>
> hi,
>
> is it possible to retrieve auth_group.role from auth_user table?
> e.g.
> # add group
> auth.add_group('Admin', 'Admin')
> auth.add_group('Cashier', 'Cashier')
> auth.add_group('Doctor', 'Doctor')
>
> # add membership (Group, User)
> auth.add_membership('1', '1')
> auth.add_membership('2', '1')
> auth.add_membership('2', '2')
> auth.add_membership('3', '3')
>
> # format_doctor
> def format_doctor(record):
> return '%s %s' % (record.user_id.first_name, record.user_id.last_name)
>
> # on_define_registration
> def on_define_registration(table):
> # requires
> # table.doctor.requires = IS_IN_DB(db(db.auth_membership.group_id == 3),
> db.auth_user.id, '%(first_name)s %(last_name)s')
> # table.doctor.requires = IS_IN_DB(db(db.auth_membership.group_id == 3),
> db.auth_membership.id, label = format_doctor)
>
> db.define_table('registration',
> Field('registration_no'),
> Field('registration_date', 'date'),
> Field('patient', 'reference patient'),
> Field('doctor', 'reference auth_user'),
> # Field('doctor', 'reference auth_membership'),
> Field('status'),
> on_define = on_define_registration,
> format = '%(registration_no)s')
>
> how can i retrieve auth_group.role from auth_user table using web2py way?
>
> thanks and best regards,
> stifan
>
--
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 the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.