Jonathan, 

Thank you for your suggestion. Session variables should work just fine for 
this indeed.

Just for future reference, I had also came up with a somewhat hacky way to 
get my navigation menus to append the sub_user.id as an argument. 
Basically, I have two navigation menus: one on the left to select the 
sub_user and one at the top for various actions pertaining to that 
sub_user. In menu.py, iterate over each sub_user and add a tab for the 
sub_user menu, appending the sub_user.id as an argument to the URL. Then, 
only add the top menu items if the current sub_user.id equals the id in the 
URL arguments. If so, set the arguments for each of those tabs to be that 
sub_user.id. In other words:

for sub_user in db(db.sub_user.auth_user_id==auth.user_id).select():
    response.sub_user_menu += [
        (str(sub_user.first_name), False, URL('dashboard', 'index', args=str
(sub_user.id)), [])]
    if request.args(0) and str(sub_user.id) == str(request.args(0)):
        response.dashboard_menu = [
            (T('Tab1'), (request.function=='tab1'), URL('dashboard', 'tab1',args
=str(sub_user.id)), []),
            (T('Tab2'), (request.function=='tab2'), URL('dashboard', 'tab2',args
=str(sub_user.id)), []),
            (T('Tab3'), (request.function=='tab3'), URL('dashboard', 'tab3',args
=str(sub_user.id)), [])]

Not sure how Pythonic this really is but it got the job done. Sessions will 
be much cleaner, though, so I'll go with that. Thank you again.



On Sunday, December 8, 2013 9:28:16 AM UTC-8, Jonathan Lundell wrote:
>
> On 8 Dec 2013, at 8:43 AM, Jonathan Lundell <jlun...@pobox.com<javascript:>> 
> wrote:
>
> On 8 Dec 2013, at 12:46 AM, Henry Nguyen <henryn...@gmail.com<javascript:>> 
> wrote:
>
> I have an application in which users can have sub_users. Within the app, a 
> user can select a sub_user, at which point, all controls become targeted to 
> that selected sub_user. For example, if I select sub_user 1 and then goto 
> "settings/show_settings.html," I want the show_settings.html to show 
> settings only for that sub_user 1. If I navigate to another page, I want 
> the controller and function to again refer only to sub_user 1. I want it to 
> stay like this until I explicitly navigate to another sub_user 2.
>
> In the case of web2py's URL mapping scheme, I assume this would mean I 
> would have to use 1 as the argument after every function in the URL. What's 
> the best way to go about ensuring this? Is this even the best way?
>
>
> Consider storing the sub_user ID in your session.
>
>
> I should point out, though, that there's a downside to this. Suppose a 
> user opens multiple tabs, and tries to work with different sub_users in 
> different tabs. That will fail, because all the tabs share the same session.
>
> If that's not an issue for you, sessions are the way to go. If it is, try 
> putting the sub_user into your forms as a hidden variable, and picking it 
> up from vars.
>
>

-- 
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.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to