wuttaweb.menus
¶
Main Menu
- class wuttaweb.menus.MenuHandler(config)[source]¶
Base class and default implementation for menu handler.
It is assumed that most apps will override the menu handler with their own subclass. In particular the subclass will override
make_menus()
and/ormake_admin_menu()
.The app should normally not instantiate the menu handler directly, but instead call
get_web_menu_handler()
on the app handler.To configure your menu handler to be used, do this within your config extension:
config.setdefault('wuttaweb.menus.handler_spec', 'poser.web.menus:PoserMenuHandler')
The core web app will call
do_make_menus()
to get the final (possibly filtered) menu set for the current user. The menu set should be a list of dicts, for example:menus = [ { 'title': "First Dropdown", 'type': 'menu', 'items': [ { 'title': "Foo", 'route': 'foo', }, {'type': 'sep'}, # horizontal line { 'title': "Bar", 'route': 'bar', }, ], }, { 'title': "Second Dropdown", 'type': 'menu', 'items': [ { 'title': "Wikipedia", 'url': 'https://en.wikipedia.org', 'target': '_blank', }, ], }, ]
- do_make_menus(request, **kwargs)[source]¶
This method is responsible for constructing the final menu set. It first calls
make_menus()
to get the basic set, and then it prunes entries as needed based on current user permissions.The web app calls this method but you normally should not need to override it; you can override
make_menus()
instead.
- make_admin_menu(request, **kwargs)[source]¶
Generate a typical Admin menu.
This method provides a semi-sane menu set by default, but it is expected for most apps to override it.
The return value for this method should be a single dict, which will ultimately be one element of the final list of dicts as described in
MenuHandler
.- Parameters:
include_people – You can pass this flag to indicate the admin menu should contain an entry for the “People” view.
- make_menus(request, **kwargs)[source]¶
Generate the full set of menus for the app.
This method provides a semi-sane menu set by default, but it is expected for most apps to override it.
The return value should be a list of dicts as described above.
The default logic returns a list of menus obtained from calling these methods:
- make_people_menu(request, **kwargs)[source]¶
Generate a typical People menu.
This method provides a semi-sane menu set by default, but it is expected for most apps to override it.
The return value for this method should be a single dict, which will ultimately be one element of the final list of dicts as described in
MenuHandler
.