websauna.system.admin.menu module

Simple mechanism to register admin menu entries.

class websauna.system.admin.menu.Entry(id, label, icon=None, caret=None, css_class=None, template=None, submenu=None, condition=None, link=None, extra=None)[source]

Bases: object

Option is one choice in a menu.

It can be a simple link, submenu or a custom rendered template.

Adding conditional entry with a permission check:

admin = Admin.get_admin(self.config.registry)
entry = menu.RouteEntry("admin-notebook", label="Shell", icon="fa-terminal", route_name="admin_shell", condition=lambda request:request.has_permission('shell'))
admin.get_root_menu().add_entry(entry)
caret = 'fa fa-caret-down'

Get the link target where this menu entry jumps to.

Return type

str

is_enabled(request)[source]

Return True if this entry is visible.

Return type

bool

render(request)[source]

Render this item to HTML.

Returns

Rendered HTML as a string

template = 'admin/menu/entry.html'
class websauna.system.admin.menu.Menu[source]

Bases: object

Menu is a collection of items in a Bootstrap pull-down menu.

It allow mechanism for third party packages to register their own entries.

add_entry(entry)[source]
get_entries()[source]

Get Entry objects to be rendered in this menu.

Sort return by natural name order.

Return type

List

get_entry(id)[source]

Get any of registered menu entries by its id.

has_items(request)[source]

Has this menu any entries to draw.

Return type

bool

template = 'admin/menu/menu.html'
class websauna.system.admin.menu.NavbarEntry(id, label, icon=None, caret=None, css_class=None, template=None, submenu=None, condition=None, link=None, extra=None)[source]

Bases: websauna.system.admin.menu.Entry

Root entry for rendering horizontal navigation list menu.

template = 'admin/menu/navbar.html'
class websauna.system.admin.menu.RouteEntry(id, label, route_name, **kwargs)[source]

Bases: websauna.system.admin.menu.Entry

Menu entry which has a Pyramid route as a link.

Get the link target where this menu entry jumps to.

class websauna.system.admin.menu.TraverseEntry(id, label, resource, name, **kwargs)[source]

Bases: websauna.system.admin.menu.Entry

Menu entry which has a Pyramid traversing context as a link.

Please note that this works only for fixed resources which are generated on the application startup.

Example:

admin = Admin.get_admin(self.config.registry)
entry = menu.TraverseEntry(id="admin-menu-phone-order", label="Create phone order", context=admin, name="phone-order", icon="fa-phone")
admin.get_admin_menu().add_entry(entry)

Get the link target where this menu entry jumps to.