Misc Widgets#

class GravatarWidget(gravatar_url: str | None = None, size: int | str | None = None, fullname: str | None = None, **kwargs: Any)[source]#

Bases: Image

Display a Gravatar profile picture as a circular image.

This widget creates a circular image that displays a user’s Gravatar profile picture. It automatically sets the appropriate styling for a responsive, rounded avatar image.

Example

from wildewidgets import GravatarWidget

# Create a standard-sized Gravatar
gravatar = GravatarWidget(
    gravatar_url="https://www.gravatar.com/avatar/hash",
    fullname="John Doe"
)

# Create a larger Gravatar
large_gravatar = GravatarWidget(
    gravatar_url="https://www.gravatar.com/avatar/hash",
    size=64,
    fullname="Jane Smith"
)
block: str = 'rounded-circle'#

The CSS block name for this widget. This is used to identify the widget in the template and to apply CSS styles.

fullname: str | None = None#

The person’s name. This will be used as the alt tag on the image

gravatar_url: str | None = None#

The gravatar URL

size: int | str = 28#

The length in pixels that will used as the height and width of the image

class InitialsAvatarWidget(*args: Any, initials: str | None = None, size: int | None = None, color: str | None = None, background_color: str | None = None, fullname: str | None = None, **kwargs: Any)[source]#

Bases: TemplateWidget

Display a person’s initials in a colored circle.

This widget creates an SVG-based avatar showing a person’s initials in a colored circle, similar to those used in many applications when a profile picture is not available.

Example

from wildewidgets import InitialsAvatarWidget

# Create an avatar with default sizing and colors
avatar = InitialsAvatarWidget(initials="JD", fullname="John Doe")

# Create a larger avatar with custom colors
custom_avatar = InitialsAvatarWidget(
    initials="AB",
    size=48,
    color="#ffffff",
    background_color="#336699",
    fullname="Alice Brown"
)
get_context_data(**kwargs: Any) dict[str, Any][source]#

Prepare the context data for template rendering.

Processes the widget parameters and adds them to the template context for rendering the SVG avatar.

Parameters:

**kwargs – Initial context dictionary

Returns:

Updated context dictionary with avatar properties

Return type:

dict

Note

The method converts initials to uppercase and calculates the half-size value needed for SVG centering.

background_color: str = '#626976'#

The background color for the gravatar

color: str = 'white'#

The foreground color for the gravatar

size: int = 28#

The length in pixels that will used as the height and width of the gravatar

template_name: str = 'wildewidgets/initials_avatar.html'#

The path to the template used to render this widget

class KeyValueListBlock(*blocks: str | wildewidgets.widgets.base.Widget | wildewidgets.widgets.base.Block, tag: str | None = None, name: str | None = None, modifier: str | None = None, css_class: str | None = None, css_id: str | None = None, empty: bool | None = None, script: str | None = None, attributes: dict[str, str] | None = None, data_attributes: dict[str, str] | None = None, aria_attributes: dict[str, str] | None = None)[source]#

Bases: Block

A list that displays key-value pairs.

This widget creates a Bootstrap list group to display key-value pairs. Each pair is rendered as a list item with the key and value positioned horizontally. The values can be simple text or code blocks with syntax highlighting.

Example

from wildewidgets import KeyValueListBlock

# Create a key-value list
kv_list = KeyValueListBlock()

# Add simple text pairs
kv_list.add_simple_key_value("Name:", "John Doe")
kv_list.add_simple_key_value("Email:", "john@example.com")

# Add a code value with syntax highlighting
kv_list.add_code_key_value(
    "JSON Response:",
    '{"status": "success", "data": {"id": 123}}',
    language="json"
)
add_code_key_value(key: Any, value: Any, language: str | None = None) None[source]#

Add a key-value pair with syntax-highlighted code as the value.

Creates a list item containing the key and a code block for the value. The code block can have syntax highlighting for a specific language.

Parameters:
  • key – The label or key to display

  • value – The code to display in the code block

Keyword Arguments:

language – Optional language identifier for syntax highlighting

add_simple_key_value(key: Any, value: Any) None[source]#

Add a simple key-value pair to the list.

Creates a list item containing the key and value positioned horizontally. Both key and value are rendered as simple text.

Parameters:
  • key – The label or key to display (left side)

  • value – The value to display (right side)

block: str = 'list-group'#

The CSS class for the container

tag: str = 'ul'#

The HTML tag to use for the container