Layout Widget#
- class WidgetIndex(*args, **kwargs)[source]#
Bases:
BlockA navigational index of widgets.
This widget creates a visual index or table of contents for a collection of widgets. Each entry in the index consists of a widget with an associated title and icon.
Note
This is not something that you would use directly.
WidgetListLayoutuses this internally when you add widgets to the main content area.- entries#
Default list of widget index items
- Parameters:
*args – Positional arguments passed to parent
- Keyword Arguments:
**kwargs – Keyword arguments which may include ‘entries’ to initialize the index with a list of
WidgetIndexItemobjects
- add_widget(widget: Widget, title: str | None = None, icon: str | None = None) None[source]#
Add a widget to the index.
Adds the given widget to the index with an associated title and icon. If title or icon are not provided, they will be determined from the widget attributes or defaults.
Note
If the widget has an is_visible function that evaluates to False, the widget will not be added to the index.
- Parameters:
widget – The widget to add to the index
title – Optional display title for the widget. If None, uses widget.title1 or the widget class name
icon – Optional icon identifier. If None, uses widget.icon or “gear”
- get_context_data(*args, **kwargs) dict[str, Any][source]#
Get context data for template rendering.
Adds the widget index entries to the template context.
- Parameters:
*args – Positional arguments passed to parent
**kwargs – Additional context variables
- Returns:
Updated context dictionary with entries
- Return type:
- block: str = 'widget-index'#
block is the official wildewidgets name of the block; it can’t be changed by constructor kwargs
- class WidgetIndexItem(widget: Widget, title: str, icon: str = 'gear')[source]#
Bases:
objectData container for items in a widget index.
This dataclass represents a single entry in a widget index, combining a widget instance with its display title and icon.
- widget#
The widget instance to be displayed in the index
- class WidgetListLayout(title: str, sidebar_title: str | None = None, sidebar_width: int | None = None, sidebar_breakpoint: str | None = None, **kwargs)[source]#
Bases:
BlockProvides a two column layout. The first column is the sidebar containing links to the various widgets in the right column, and the second column is the main content, consisting of the contained widgets vertically stacked.
This is really the only class you need to use to create a page with a sidebar and a main content area. You can add widgets to the sidebar and the main content area, and they will be displayed in the appropriate places.
Example
from wildewidgets import WidgetListLayout from django.urls import reverse from core.widgets import Widget1, Widget2, Widget3 layout = WidgetListLayout('My Page') layout.add_sidebar_form_button('Update', reverse('core:thing--update')) layout.add_widget(Widget1(), title='another title') layout.add_widget(Widget2(), title='the title', icon='stuff') layout.add_widget(Widget3())
- Keyword Arguments:
title – The title of the widget.
sidebar_title – the title of the sidebar column
sidebar_width – the width in columns of the sidebar column
sidebar_breakpoint – the breakpoint at which the sidebar will collapse to a hamburger menu. Defaults to “xl” (extra large).
**kwargs – Additional keyword arguments passed to the parent *
wildewidgets.Blockclass
- add_modal(modal: Widget) None[source]#
Add a modal widget to the layout.
Modals are typically used for dialogs or secondary content that overlays the main content.
- Parameters:
modal – The modal widget to add
- Returns:
None
- add_sidebar_bare_widget(widget: Widget) None[source]#
Add a bare widget to the sidebar.
Bare widgets are added outside the Actions area and are not subject to special styling.
- Parameters:
widget – The widget to add to the sidebar
- add_sidebar_form_button(text: str, action: str, **kwargs) None[source]#
Add a form button to the sidebar.
This method simplifies the addition of form buttons to the sidebar with appropriate styling and behavior.
- Parameters:
text – The text to display on the button
action – The form action URL that the button should submit to
**kwargs – Additional keyword arguments for customization
- add_sidebar_link_button(text: str, url: str, **kwargs) None[source]#
Add a link button to the sidebar.
This method simplifies the addition of link buttons to the sidebar with appropriate styling and behavior.
- Parameters:
text – The text to display on the button
url – The URL that the button should link to
**kwargs – Additional keyword arguments for customization
- add_sidebar_widget(widget: Widget) None[source]#
Add a widget to the sidebar.
This method adds the widget to the Actions area of the sidebar, typically used for secondary actions or information.
- Parameters:
widget – The widget to add to the sidebar
- add_widget(widget: Widget, title: str | None = None, icon: str | None = None) None[source]#
Add a widget to the layout.
This method adds the widget to both the sidebar index and the main content area.
- Parameters:
widget – The widget to add
title – Optional title for the widget
icon – Optional icon for the widget
- get_context_data(*args, **kwargs) dict[str, Any][source]#
Get context data for template rendering.
Provides the layout with the necessary context variables for rendering the title, sidebar, main content, and any modals.
- Parameters:
*args – Positional arguments passed to parent
**kwargs – Additional context variables
- Returns:
Updated context dictionary with layout components
- Return type:
- class WidgetListMainWidget(*args, **kwargs)[source]#
Bases:
BlockThe main content area in a widget list layout.
This widget represents the primary content area where widgets are displayed in a vertical stack. It’s typically used in conjunction with a sidebar widget to create a comprehensive layout.
Note
This is not something that you would use directly.
WidgetListLayoutuses this internally when you add widgets to the main area.- entries#
Default list of widget index items for the main content
- Parameters:
*args – Positional arguments passed to parent
- Keyword Arguments:
**kwargs – Keyword arguments which may include ‘entries’ to initialize the list with a list of WidgetIndexItem objects
- add_widget(widget: Widget, title: str | wildewidgets.widgets.base.Widget | None = None) None[source]#
Add a widget to the main content area.
This method also ensures that the widget has an associated title, either from the widget itself or as a provided argument.
- Parameters:
widget – The widget to add to the main content area
title – Optional title for the widget. If provided, it will be set as the widget’s title attribute
- get_context_data(*args, **kwargs) dict[str, Any][source]#
Get context data for template rendering.
Provides the list of entries to be rendered in the main widget area.
- Parameters:
*args – Positional arguments passed to parent
**kwargs – Additional context variables
- Returns:
Updated context dictionary with entries and CSS classes
- Return type:
- class WidgetListSidebarWidget(*args, title: str | None = None, width: int = 3, breakpoint: str = 'xl', bare_widgets: list[wildewidgets.widgets.base.Widget] | None = None, actions: list[wildewidgets.widgets.base.Widget] | None = None, **kwargs)[source]#
Bases:
BlockA sidebar component for widget list layouts.
This widget creates a sidebar that can contain actions (typically buttons) and other widgets. It’s commonly used as part of a WidgetListLayout to provide navigation and action controls.
Note
This is not something that you would use directly.
WidgetListLayoutuses this internally when you add widgets to the sidebar area.- actions#
Default list of action widgets to display
- bare_widgets#
Default list of widgets to display without special styling
- Parameters:
*args – Positional arguments passed to parent
- Keyword Arguments:
title – Optional title for the sidebar
width – Column width for the sidebar, defaults to 3
breakpoint – Bootstrap breakpoint for responsive design
bare_widgets – Optional list of widgets to display without special styling
actions – Optional list of action widgets to display
**kwargs – Additional keyword arguments passed to parent
- class Actions(widgets: list[wildewidgets.widgets.base.Widget] | None = None, **kwargs: Any)[source]#
Bases:
WidgetStream
- class Widgets(widgets: list[wildewidgets.widgets.base.Widget] | None = None, **kwargs: Any)[source]#
Bases:
WidgetStream
- add_actions_widget(widget: Widget) None[source]#
Add a widget to the sidebar inside the Actions box.
- add_form_button(text: str, action: str, **kwargs) None[source]#
Add
wildewidgets.FormButtonto the sidebar.- Parameters:
text – The text to display on the button.
action – The action to perform when the button is clicked.
- Keyword Arguments:
**kwargs – any additional keyword arguments appropriate for
wildewidgets.FormButton
- add_link_button(text: str, url: str, **kwargs) None[source]#
Add
wildewidgets.LinkButtonto the sidebar.- Parameters:
text – The text to display on the button.
url – The URL to link to.
- Keyword Arguments:
**kwargs – any additional keyword arguments appropriate for
wildewidgets.FormButton
- add_widget_to_index(widget: Widget, title: str | None = None, icon: str | None = None) None[source]#
Add
widgetthe index with titletitleand iconicon.If
titleisNone, look for a title onwidget.title. If that is alsoNone, default to the name of the widget class.If
iconisNone, look for an icon onwidget.icon. If that is alsoNone, default to the Bootstrap Icons “gear” icon.
- get_context_data(*args, **kwargs) dict[str, Any][source]#
Update the template context dictionary used when rendering this block.
- Parameters:
*args – positional arguments (ignored)
- Keyword Arguments:
**kwargs – the current context dictionary
- Returns:
The updated context dictionary