Structure Widgets#
- class CardWidget(*blocks, header: Optional[BasicHeader] = None, header_text: Optional[str] = None, header_css: Optional[str] = None, card_title: Optional[str] = None, card_subtitle: Optional[str] = None, widget: Optional[Widget] = None, widget_css: Optional[str] = None, overflow: Optional[str] = None, **kwargs)[source]#
Bases:
Block
Renders a Bootstrap 5 Card.
- Keyword Arguments:
header – A header widget to display above the card.
header_text – Text used to build a header widget is one is not provided
card_title – Card title
card_subtitle – Card subtitle
widget – Widget to display in card body
widget_css – CSS to apply to the widget displayed in the card body
css_class – CSS to apply to the card itself in addition to the defaults
overflow –
- get_context_data(*args, **kwargs)[source]#
Update the template context dictionary used when rendering this block.
- Keyword Arguments:
**kwargs – the current context dictionary
- Returns:
The updated context dictionary
- set_header(header)[source]#
Set the header widget to display above the card
- Parameters:
header (obj) – Header widget to display above the card
- set_widget(widget, css_class=None)[source]#
Set the widget displayed in the card body
- Parameters:
widget (obj) – Widget to display in card body
css_class (str) – CSS to apply to the widget displayed in the card body
- class CollapseWidget(*blocks, tag: Optional[str] = None, name: Optional[str] = None, modifier: Optional[str] = None, css_class: Optional[str] = None, css_id: Optional[str] = None, empty: Optional[bool] = None, script: Optional[str] = None, attributes: Optional[Dict[str, str]] = None, data_attributes: Optional[Dict[str, str]] = None, aria_attributes: Optional[Dict[str, str]] = None)[source]#
Bases:
Block
It is typically used in conjunction with a
CollapseButton
. Pressing theCollapseButton
toggles the visibility of the widget.Example
>>> collapse_id = 'my-collapse-id' >>> collapse = CollapseWidget( CrispyFormWidget(form=form), css_id=collapse_id, css_class="pt-3", ) >>> header = CardHeader(header_text="Services") >>> header.add_collapse_button( text="Manage", color="primary", target=f"#{collapse_id}", )
- Keyword Arguments:
css_id – This ID will be shared with the
CollapseButton
.
- class HorizontalLayoutBlock(*blocks, align: Optional[str] = None, justify: Optional[str] = None, flex_size: Optional[str] = None, **kwargs)[source]#
Bases:
Block
A container widget intended to display several other widgets aligned horizontally.
Example
>>> layout = HorizontalLayoutBlock( LabelBlock(label), block1, block2, justify="end", css_class="mt-3", )
- Keyword Arguments:
align – how to align items veritcally within this widget. Valid choices:
start
,center
,end
,baselin
,stretch
. See Bootstrap: Flex, justify content. If not supplied here andalign
isNone
, do whatever vertical aligment Bootstrap does by default.justify –
how to align items horizontally within this widget. Valid choices:
start
,center
,end
,between
,around
,evenly
. See Bootstrap: Flex, justify content. If not supplied here andjustify
isNone
, do whatever horizontal aligment Bootstrap does by default.flex_size – the Boostrap viewport size below which this will be a vertical list instead of a horizontal one.
- VALID_ALIGNMENTS: List[str] = ['start', 'center', 'end', 'baseline', 'stretch']#
The valid column content
justify-content-
values
- VALID_JUSTIFICATIONS: List[str] = ['start', 'center', 'end', 'between', 'around', 'evenly']#
The valid column content
justify-content-
values
- align: str = 'center'#
start
,center
,end
,baselin
,stretch
. See Bootstrap: Flex, justify content. If not supplied here andalign
isNone
, do whatever vertical aligment Bootstrap does by default.- Type:
How to align items veritcally within this widget. Valid choices
- flex_size: Optional[str] = None#
the Boostrap viewport size below which this will be a vertical list instead of a horizontal one.
- justify: str = 'between'#
start
,center
,end
,between
,around
,evenly
. See Bootstrap: Flex, justify content. If not supplied here andjustify
isNone
, do whatever horizontal aligment Bootstrap does by default.- Type:
How to align items horizontally within this widget. Valid choices
- class ListModelCardWidget(*args, list_model_widget_class: Optional[Type[Widget]] = None, list_model_header_class: Optional[Type[Widget]] = None, **kwargs)[source]#
Bases:
CardWidget
This class provides a
CardWidget
with a header and a list of objects defined by aQuerySet
, displayed in aListModelWidget
. A filter input is provided to filter the list of objects.Example
>>> widget = ListModelCardWidget( queryset = Author.objects.all()[:10] )
- Keyword Arguments:
list_model_widget_class – The class to use for the list model widget. The default is
ListModelWidget
.list_model_header_class – The class to use for the header.
- list_model_widget_class#
alias of
ListModelWidget
- class ListModelWidget(*args, remove_url=None, **kwargs)[source]#
Bases:
MultipleModelWidget
This class provides a list of objects defined by a
QuerySet
, displayed in a “list-group
”<ul>
block. By default, a widget will be provided that simply displays whatever returns from the conversion of the object to astr
. If aremove_url
is provided, an X icon to the right of each object will act as a button to remove the item.Example
>>> widget = ListModelWidget( queryset=myparent.children, item_label='child', remove_url=reverse('remove_url') + "?id={}", )
- Parameters:
remove_url – The url to “POST” to in order to delete or remove the object.
- get_model_widget(object: Optional[Model] = None, **kwargs)[source]#
Returns the individual widget to display as part of the list.
- Parameters:
object – the model instance to pass into the model specific widget
- block: str = 'list-group'#
block is the official wildewidgets name of the block; it can’t be changed by constructor kwargs
- class MultipleModelWidget(*blocks, model: Optional[Type[Model]] = None, queryset: Optional[QuerySet] = None, ordering: Optional[str] = None, model_widget: Optional[Widget] = None, model_kwargs: Optional[Dict[str, Any]] = None, item_label: Optional[str] = None, **kwargs)[source]#
Bases:
Block
Base class for
PagedModelWidget
andListModelWidget
.- Keyword Arguments:
model – if this is defined, do
self.model.objects.all()
to get our list of instances. Define either this orqueryset
, but not both.queryset – use this queryset to get our list of instances. Define either this or
model
, but not both.ordering – the ordering to use for the queryset. This will be applied to both
model
andqueryset
model_widget – use this widget class to render each model instance.
model_kwargs – When instantiating
model_widget
, pass this dict into the widget constructor as the keyword argumentsitem_label – The label to use for each instance. This is used in the confirmation dialog when deleting instances.
- get_item_label(instance: Model) str [source]#
Returns the type of the item displayed. This is used in the confirmation dialog when deleting.
- get_model_widget(object: Model, **kwargs) Widget [source]#
Returns the individual widget to display as part of the list.
- Parameters:
object – the model instance to pass into the model specific widget
- get_queryset() Union[List[Model], QuerySet] [source]#
Return the list of items for this widget.
The return value must be an iterable and may be an instance of
QuerySet
in which case query set specific behavior will be enabled.
- item_label: str = 'item'#
The label to use for each instance. This is used in the confirmation dialog when deleting instances.
- model: Type[Model] = None#
If this is defined, do
self.model.objects.all()
to get our list of instances. Define either this orqueryset
, but not both.
- model_kwargs: Dict[str, Any] = {}#
When instantiating
model_widget
, pass this dict into the widget constructor as the keyword arguments
- class PagedModelWidget(*blocks, page_kwarg: Optional[str] = None, paginate_by: Optional[int] = None, extra_url: Optional[Dict[str, Any]] = None, **kwargs)[source]#
Bases:
MultipleModelWidget
A widget that displays a pageable list of widgets defined by a queryset. A model or queryset must be provided, and either a model_widget or the funtion get_model_widget must be provided.
- Parameters:
Example:
>>> widget = PagedModelWidget( queryset=mymodel.myobject_set.all(), paginate_by=3, page_kwarg='myobject_page', model_widget=MyObjectWidget, model_kwargs={'foo': bar}, item_label="myobject", extra_url={ 'pk': myobject.id, '#':'myobjects', }, )
- get_context_data(*args, **kwargs)[source]#
Update the template context dictionary used when rendering this block.
- Keyword Arguments:
**kwargs – the current context dictionary
- Returns:
The updated context dictionary
- class TabbedWidget(*blocks, slug_suffix: Optional[str] = None, overflow: Optional[str] = None, **kwargs)[source]#
Bases:
Block
This class implements a Tabler Tabbed Card.
Example
>>> tab = TabbedWidget() >>> tab.add_tab('My First Widget', widget1) >>> tab.add_tab('My Second Widget', widget2)
- add_tab(name: str, widget: Block) None [source]#
Add a Bootstrap 5 tab named name that displays widget.
- Parameters:
name – the name of the tab
widget – the block to display in this tab
- get_context_data(*args, **kwargs)[source]#
Update the template context dictionary used when rendering this block.
- Keyword Arguments:
**kwargs – the current context dictionary
- Returns:
The updated context dictionary