Create a custom tile type
See the built-in reference for the definition fields and available built-ins.
Register a tile with typed settings and a renderer
Define a small configuration model and render the message using Django’s HTML escaping.
python
from typing import Self
from django.http import HttpRequest
from django.utils.html import format_html
from pydantic import Field
from bloomerp.workspaces.base import BaseTileConfig, BaseTileRenderer, TileOperationDefinition, TileTypeDefinition
from bloomerp.workspaces.registry import TILE_TYPE_REGISTRY
class NoticeTileConfig(BaseTileConfig):
'''Store the text displayed in a notice tile.'''
message: str = Field(default="Dispatch is open.", description="Text shown to users.")
@classmethod
def get_default(cls) -> Self:
'''Build a notice with the default message.'''
return cls()
@classmethod
def get_operation(cls, operation: str) -> TileOperationDefinition:
'''Reject operations because the notice has no interactive controls.'''
raise KeyError(operation)
class NoticeTileRenderer(BaseTileRenderer):
'''Render the notice as an escaped paragraph.'''
@classmethod
def render(cls, config: NoticeTileConfig, request: HttpRequest) -> str:
'''Return the configured message inside a paragraph.'''
return format_html("<p>{}</p>", config.message)
TILE_TYPE_REGISTRY.register(
TileTypeDefinition(
id="EXAMPLE_NOTICE_TILE",
name="Notice",
description="Show a short notice on a workspace.",
model=NoticeTileConfig,
render_cls=NoticeTileRenderer,
),
)Place the new tile on a module workspace
Use the notice configuration from the previous example. Match the layout item ID to the configured tile ID.
python
from bloomerp.models.definition import LayoutItem, LayoutRow, WorkspaceLayout
from bloomerp.modules.definition import BloomerpModule
class DispatchWorkspaceModule(BloomerpModule):
'''Publish a dispatch workspace with a notice tile.'''
id = "dispatch_board"
name = "Dispatch board"
tiles = [
NoticeTileConfig(id="dispatch-notice", message="Review today's deliveries."),
]
workspaces = [
WorkspaceLayout(
rows=[LayoutRow(columns=1, items=[LayoutItem(id="dispatch-notice")])],
),
]