Dynamic menus

99 views
Skip to first unread message

Tomas Schertel

unread,
Oct 15, 2012, 3:37:41 PM10/15/12
to we...@googlegroups.com
Hi every body!

I'm planning to have different access profiles in an application I'm writing.
How can I have a different menu for each access profile?
I'm wondering how accomplish it, but I'm kind of stuck...

Can someone help?

Thanks.

Shannon Cruey

unread,
Oct 15, 2012, 5:55:09 PM10/15/12
to we...@googlegroups.com
It's a bit unusual but here's what I do. 

My menu is a static HTML file called _x_menu.html. Using jquery Ajax, I load that into the header div on page load. 

Now here's the magic. There are multiple menu files, one for each user "level" ( i have 4). My get_menu web method determines which menu to deliver. 

Hack proof? No, but it'd take some savvy. So, as a final protection mechanism, I have a hash in my python code that associates content with user levels. That way, even if a user did try to directly access a forbidden page, the auth_processor would deny the request. 

Make sense?
--
You received this message because you are subscribed to the Google Groups "web.py" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webpy/-/VTruxTA7McoJ.
To post to this group, send email to we...@googlegroups.com.
To unsubscribe from this group, send email to webpy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webpy?hl=en.

Tomas Schertel

unread,
Oct 16, 2012, 4:30:53 PM10/16/12
to we...@googlegroups.com
Could I have a specific render for my menus and concatenate my base html with my menu and the page body?

Shannon Cruey

unread,
Oct 17, 2012, 4:44:51 PM10/17/12
to we...@googlegroups.com
Tomas, I use the templating very little, as most of my code is Ajax, but I originally did this with templates.  I think you can do what you're suggesting, by building your menu in python and passing the text to the render function.

I think you prefer to avoid ajax and inject the menu into the render?  So, assuming you already built your menu html into a string:

admin_menu = "some html"
class home:       
    def GET(self):
        return render.home(admin_menu)

Then, in the home.html file in the templates directory, the first line would be:
$def with (content, menuhtml)

and somewhere on the page you'd have:
<div id="menu">$menuhtml</div>

I never did this with the 'base' template, but I'm sure it's similar.

Good luck!
S




To view this discussion on the web visit https://groups.google.com/d/msg/webpy/-/gLA0GFeMeg0J.

Tomas Schertel

unread,
Oct 19, 2012, 7:31:03 AM10/19/12
to we...@googlegroups.com
Thanks NSC. I'll try it.
Reply all
Reply to author
Forward
0 new messages