Navigation
Module reahl.web.bootstrap.navs¶
Added in version 3.2.
A Bootstrap “Nav” is a navigation menu: a list of items that are links to other Views. Navs can also have a second level so that if you click on an item, a dropdown list of vertically stacked options appear.
This module contains the necessary Widgets and Layouts to create and style Bootstrap Navs.
Changed in version 4.0: Moved Menu here from reahl.web.ui.
Changed in version 4.0: Removed the .add_item and add_submenu methods in favour of .add_a,.add_bookmark,.add_dropdown methods.
Nav¶
- class reahl.web.bootstrap.navs.Nav(view)¶
Bases:
Menu
A Nav is a navigation menu, with items a user can click on to transition to possibly different Views. Individual Items visually indicate whether they are active or disabled.
Note
Don’t be confused
This, the
reahl.web.bootstrap.navs.Nav
is not the same thing as a simple HTML-levelreahl.web.bootstrap.ui.Nav
!- Parameters:
view – (See
Widget
)
- query_fields¶
Used to declare the arguments of this Widget on its class.
Override this class attribute to declare arguments this Widget, each described by a
Field
.When constructed, the Widget uses the names and validation details of each Field to parse values for its arguments from the current query string. The resultant argument values are set as attributes on this Widget (with names matching the argument names).
To declare arguments on your own Widget class, assign a ExposedNames instance to query_fields and then assign a single-argument callable for each Widget argument to it. This callable will be called with the Widget instance as argument, and should return a
Field
describing it:class MyWidget(Widget): query_fields = ExposedNames() query_fields.my_argument = lambda i: Field()
Changed in version 6.1: This used to be set up using a method using an
exposed
decorator.
- add_dropdown(title, dropdown_menu, drop_position='down', query_arguments={})¶
Adds the dropdown_menu
DropdownMenu
to this Nav. It appears as the top-level item with text title.- Parameters:
drop_position – Position relative to the item where the dropdown should appear (‘up’, ‘down’, ‘left’ or ‘right’).
query_arguments – (For internal use)
PillLayout¶
- class reahl.web.bootstrap.navs.PillLayout(stacked=False, content_alignment=None, content_justification=None)¶
Bases:
NavLayout
This Layout makes a Nav appear as horizontally or vertically arranged pills (buttons).
- Parameters:
stacked – If True, the pills are stacked vertically.
content_alignment – If given, changes how content is aligned inside the Nav (default is start) (One of: center, end)
content_justification – If given, makes the content take up all space in the Nav. Either with elements having equal space (fill), or unequal space (justified) (One of: fill, justified)
- customise_widget()¶
Override this method in subclasses to allow your Layout to change its Widget upon construction. There is no need to call super(), as the superclass implementation does nothing.
TabLayout¶
- class reahl.web.bootstrap.navs.TabLayout(content_alignment=None, content_justification=None)¶
Bases:
NavLayout
This Layout makes a Nav appear as horizontal tabs.
- Parameters:
content_alignment – If given, changes how content is aligned inside the Nav (default is start) (One of: center, end)
content_justification – If given, makes the content take up all space in the Nav. Either with elements having equal space (fill), or unequal space (justified) (One of: fill, justified)
DropdownMenu¶
DropdownMenuLayout¶
- class reahl.web.bootstrap.navs.DropdownMenuLayout(align_right=False)¶
Bases:
Layout
Changes a DropdownMenu alignment.
- Parameters:
align_right – If True, align the dropdown to the right side of its parent item, else to the left.
- customise_widget()¶
Override this method in subclasses to allow your Layout to change its Widget upon construction. There is no need to call super(), as the superclass implementation does nothing.
Menu¶
- class reahl.web.bootstrap.navs.Menu(view)¶
Bases:
HTMLWidget
A visual menu that lists a number of Views to which the user can choose to go to.
Styling
Rendered as a <ul class=”reahl-menu”> element that contains a <li> for each MenuItem.
- Parameters:
view – (See
reahl.web.fw.Widget
)
Changed in version 3.2: Deprecated use of a_list and changed it temporarily to a keyword argument for backwards compatibility.
Changed in version 3.2: Deprecated css_id keyword argument.
Changed in version 3.2: Deprecated the from_xxx methods and added with_xxx replacements to be used after construction.
Changed in version 3.2: Deprecated add_item and replaced it with add_submenu.
Changed in version 3.2: Added a number of add_xxx methods for adding items from different sources.
Changed in version 4.0: Removed deprecated a_list and css_id
- with_bookmarks(bookmark_list)¶
Populates this Menu with a MenuItem for each Bookmark given in bookmark_list.
Answers the same Menu.
Added in version 3.2.
- with_languages()¶
Populates this Menu with a MenuItem for each available language.
Answers the same Menu.
Added in version 3.2.
- with_a_list(a_list)¶
Populates this Menu with a MenuItem for each
A
in a_list.Answers the same Menu.
Added in version 3.2.
- add_bookmark(bookmark, active_regex=None)¶
Adds a MenuItem for the given
Bookmark
to this Menu’.Answers the added MenuItem.
Added in version 3.2.
- add_a(a, active_regex=None, exact_match=None)¶
Adds an
A
as a MenuItem.Answers the added MenuItem.
Added in version 3.2.