Re: [web2py] Re: Setting a default reference value as that of a specific group the logging in user is a member of

2020-02-26 Thread villas
Naturally you can still use auth to identify the user.  
The auth groups is really just to identify the type of user,  e.g. 
teachers, students, admins. This is useful for allowing access to certain 
functionality.
You must still design your DB and create links between your tables using 
relational keys/ids.  This can get rather complex.  For example, a teacher 
might work at more than one school.  Start off by drawing a diagram to 
connect all your tables.



On Wednesday, 26 February 2020 08:36:22 UTC, AGRogers wrote:
>
> Thanks for the extra info. In my scenario I have schools, teachers, 
> subjects, classes and students. At the Classes level there will be hundreds 
> eventually (new ones each term). Your school limits what subjects you can 
> see. The teacher limits what classes she can see etc. 
>
> If I understood you correctly you are suggesting to use the auth 
> functionality built into web2py. Do you think that is still appropriate 
> when there are potentially hundreds of groups?
>
> And second, I think I read that py4web uses a different approach with 
> tags(?) Is that correct? 
>
> Thanks 
>
> On Wed, 26 Feb 2020, 15:43 'Annet' via web2py-users, <
> web...@googlegroups.com > wrote:
>
>> I don't understand the use of field 'groups' and function 'get_groups()
>>
>> I think you should use web2py's built in auth_ functionality: drop field
>> 'groups' in both tables, link users and groups (each hotel its own group)
>> in the auth_membership table, and use this table to create a list of 
>> options
>> for the drop-down.
>>
>> I hope this points you in the right direction to solve your problem
>>
>>
>> Kind regards,
>>
>> Annet
>>
>> -- 
>> 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 web...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/web2py/bd2e0505-00f8-4403-9e3d-f89372e2f027%40googlegroups.com
>>  
>> 
>> .
>>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/8710dad0-fd36-4d21-8d44-2039aab256a6%40googlegroups.com.


Re: [web2py] Re: Setting a default reference value as that of a specific group the logging in user is a member of

2020-02-26 Thread AGRogers
Thanks for the extra info. In my scenario I have schools, teachers,
subjects, classes and students. At the Classes level there will be hundreds
eventually (new ones each term). Your school limits what subjects you can
see. The teacher limits what classes she can see etc.

If I understood you correctly you are suggesting to use the auth
functionality built into web2py. Do you think that is still appropriate
when there are potentially hundreds of groups?

And second, I think I read that py4web uses a different approach with
tags(?) Is that correct?

Thanks

On Wed, 26 Feb 2020, 15:43 'Annet' via web2py-users, <
web2py@googlegroups.com> wrote:

> I don't understand the use of field 'groups' and function 'get_groups()
>
> I think you should use web2py's built in auth_ functionality: drop field
> 'groups' in both tables, link users and groups (each hotel its own group)
> in the auth_membership table, and use this table to create a list of
> options
> for the drop-down.
>
> I hope this points you in the right direction to solve your problem
>
>
> Kind regards,
>
> Annet
>
> --
> 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 web2py+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/bd2e0505-00f8-4403-9e3d-f89372e2f027%40googlegroups.com
> 
> .
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CACWMBMP6v_o%2B9Fev_z6yq9XT5agyVc-Y5E1tQcm5mu6MWgUFXA%40mail.gmail.com.


[web2py] Re: Setting a default reference value as that of a specific group the logging in user is a member of

2020-02-25 Thread 'Annet' via web2py-users
I don't understand the use of field 'groups' and function 'get_groups()

I think you should use web2py's built in auth_ functionality: drop field
'groups' in both tables, link users and groups (each hotel its own group)
in the auth_membership table, and use this table to create a list of options
for the drop-down.

I hope this points you in the right direction to solve your problem


Kind regards,

Annet

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/bd2e0505-00f8-4403-9e3d-f89372e2f027%40googlegroups.com.


[web2py] Re: Setting a default reference value as that of a specific group the logging in user is a member of

2020-02-25 Thread mostwanted
How do I set it as a default if the form is not open by a link redirection? 
The form is opened directly by the main-menu.
If it were opened through the link then it'd be easy to set the hotel as a 
default coz all i'd do would be:


*hotel=db(db.hotel_profile(request.args(0, 
cast=int))db.meals.hotel.default=hotel.id*

Please pardon my limited skill but your assistance would take me to the 
next phase of this project.

Regards

On Tuesday, February 25, 2020 at 9:06:55 PM UTC+2, villas wrote:
>
> Set the default hotel value in the SQLFORM field.
>
> You could also 'force' the hotel you want by using SQLFORM onvalidation 
> 
>
>
>
> On Tuesday, 25 February 2020 07:28:31 UTC, mostwanted wrote:
>>
>> I have 2 tables about a hotel, one table registers the hotel itself & the 
>> other is about meals that are offered at the hotel but the idea is that 
>> only group members of each hotel have to & can only register meals for 
>> their hotels. So to avoid mistakes & prevent malicious intentions I was 
>> wondering if its possible to have the referencing field in the meals table 
>> pre-selected appropriately for the logged in user with their correct hotel 
>> name as per the group they belong to. I hope I make sense:
>>
>> *MODEL CODE*
>> def get_group():
>> groups = auth.user_groups
>> if not groups:
>> return None
>> group_ids = [id for id in groups if not 
>> groups[id].startswith('user_')]
>> return group_ids[0] if group_ids else None
>>
>> db.define_table('hotel_profile',
>> Field('hotel_name'),
>> Field('logo', 'upload'),
>> Field('tel1'),
>> Field('email_address'),
>> Field('directions', 'text', requires=IS_LENGTH(500)),
>> Field('google_directions'),
>> Field('posted_by', 'reference auth_user', default=auth.
>> user_id, readable=False, writable=False),
>> Field('groups', 'reference auth_group', default=get_group
>> (), readable=False, writable=False),
>> format='%(hotel_name)s'
>>)
>>
>>
>> db.define_table('meals',
>> Field('hotel', 'reference hotel_profile'),
>> Field('supper_price'),
>> Field('supper_details', 'text', requires=IS_LENGTH(200)),
>> Field('lunch_price'),
>> Field('lunch_details', 'text', requires=IS_LENGTH(200)),
>> Field('breakfast_price'),
>> Field('breakfast_details', 'text', requires=IS_LENGTH(200
>> )),
>> Field('posted_by', 'reference auth_user', default=auth.
>> user_id, readable=False, writable=False),
>> Field('groups', 'reference auth_group', default=get_group
>> (), readable=False, writable=False)
>>)
>>
>> Regards;
>>
>> Mostwanted
>>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/c1d70cd1-a891-44dd-a73d-a0d15655c561%40googlegroups.com.


[web2py] Re: Setting a default reference value as that of a specific group the logging in user is a member of

2020-02-25 Thread villas
Set the default hotel value in the SQLFORM field.

You could also 'force' the hotel you want by using SQLFORM onvalidation 




On Tuesday, 25 February 2020 07:28:31 UTC, mostwanted wrote:
>
> I have 2 tables about a hotel, one table registers the hotel itself & the 
> other is about meals that are offered at the hotel but the idea is that 
> only group members of each hotel have to & can only register meals for 
> their hotels. So to avoid mistakes & prevent malicious intentions I was 
> wondering if its possible to have the referencing field in the meals table 
> pre-selected appropriately for the logged in user with their correct hotel 
> name as per the group they belong to. I hope I make sense:
>
> *MODEL CODE*
> def get_group():
> groups = auth.user_groups
> if not groups:
> return None
> group_ids = [id for id in groups if not groups[id].startswith('user_')]
> return group_ids[0] if group_ids else None
>
> db.define_table('hotel_profile',
> Field('hotel_name'),
> Field('logo', 'upload'),
> Field('tel1'),
> Field('email_address'),
> Field('directions', 'text', requires=IS_LENGTH(500)),
> Field('google_directions'),
> Field('posted_by', 'reference auth_user', default=auth.
> user_id, readable=False, writable=False),
> Field('groups', 'reference auth_group', default=get_group
> (), readable=False, writable=False),
> format='%(hotel_name)s'
>)
>
>
> db.define_table('meals',
> Field('hotel', 'reference hotel_profile'),
> Field('supper_price'),
> Field('supper_details', 'text', requires=IS_LENGTH(200)),
> Field('lunch_price'),
> Field('lunch_details', 'text', requires=IS_LENGTH(200)),
> Field('breakfast_price'),
> Field('breakfast_details', 'text', requires=IS_LENGTH(200
> )),
> Field('posted_by', 'reference auth_user', default=auth.
> user_id, readable=False, writable=False),
> Field('groups', 'reference auth_group', default=get_group
> (), readable=False, writable=False)
>)
>
> Regards;
>
> Mostwanted
>

-- 
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 web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/6b559611-3db8-4756-8bdc-aa99103581ea%40googlegroups.com.