Skip to content

Render

render

Functions:

Name Description
format_datetime

Format a datetime as a string using the configured datetime format.

human_readable

Convert a value to a human-readable string.

print_error

Print a styled error message to the terminal in red.

print_success

Print a styled success message to the terminal in green.

print_warning

Print a styled warning message to the terminal in yellow.

render_boolean

Render a boolean as a check symbol or an empty string.

render_maintainers

Render maintainer GitHub avatars as inline HTML image links.

render_markdown_table

Render a plain Markdown table from a header row and data rows.

render_table

Render a list of rows as a GitHub-flavoured Markdown table.

sanitize_cell

Collapse internal whitespace in a table cell value.

format_datetime

format_datetime(dt: datetime) -> str

Format a datetime as a string using the configured datetime format.

Parameters:

Name Type Description Default

dt

datetime

Datetime object to format.

required

Returns:

Type Description
str

Formatted datetime string.

Source code in oops/utils/render.py
def format_datetime(dt: datetime) -> str:
    """Format a datetime as a string using the configured datetime format.

    Args:
        dt: Datetime object to format.

    Returns:
        Formatted datetime string.
    """

    return dt.strftime(config.datetime_format)

human_readable

human_readable(raw: Any, sep: str = ', ', width: Optional[int] = None) -> str

Convert a value to a human-readable string.

Booleans become yes/no; collections are joined; strings are optionally truncated to a maximum width.

Parameters:

Name Type Description Default

raw

Any

Value to render.

required

sep

str

Separator used to join collection items. Defaults to ", ".

', '

width

Optional[int]

If provided, truncate the result to this many characters. Defaults to None.

None

Returns:

Type Description
str

Human-readable string representation of raw.

Source code in oops/utils/render.py
def human_readable(raw: Any, sep: str = ", ", width: Optional[int] = None) -> str:
    """Convert a value to a human-readable string.

    Booleans become ``yes``/``no``; collections are joined; strings are optionally
    truncated to a maximum width.

    Args:
        raw: Value to render.
        sep: Separator used to join collection items. Defaults to ", ".
        width: If provided, truncate the result to this many characters. Defaults to None.

    Returns:
        Human-readable string representation of raw.
    """

    if isinstance(raw, bool):
        return "yes" if raw else "no"
    if isinstance(raw, (list, tuple, set)):
        return sep.join(map(str, raw))

    if width:
        return textwrap.shorten(raw, width=width, placeholder="...")

    return str(raw)

print_error

print_error(message: str, symbol: str = '✘') -> None

Print a styled error message to the terminal in red.

Parameters:

Name Type Description Default

message

str

Text to display.

required

symbol

str

Prefix symbol. Defaults to "✘".

'✘'
Source code in oops/utils/render.py
def print_error(message: str, symbol: str = "✘") -> None:
    """Print a styled error message to the terminal in red.

    Args:
        message: Text to display.
        symbol: Prefix symbol. Defaults to "✘".
    """
    click.echo(click.style(f"{symbol} {message}", fg="red"))

print_success

print_success(message: str, symbol: str = '✔') -> None

Print a styled success message to the terminal in green.

Parameters:

Name Type Description Default

message

str

Text to display.

required

symbol

str

Prefix symbol. Defaults to "✔".

'✔'
Source code in oops/utils/render.py
def print_success(message: str, symbol: str = "✔") -> None:
    """Print a styled success message to the terminal in green.

    Args:
        message: Text to display.
        symbol: Prefix symbol. Defaults to "✔".
    """
    click.echo(click.style(f"{symbol} {message}", fg="green"))

print_warning

print_warning(message: str, symbol: str = '⚠') -> None

Print a styled warning message to the terminal in yellow.

Parameters:

Name Type Description Default

message

str

Text to display.

required

symbol

str

Prefix symbol. Defaults to "⚠".

'⚠'
Source code in oops/utils/render.py
def print_warning(message: str, symbol: str = "⚠") -> None:
    """Print a styled warning message to the terminal in yellow.

    Args:
        message: Text to display.
        symbol: Prefix symbol. Defaults to "⚠".
    """
    click.echo(click.style(f"{symbol} {message}", fg="yellow"))

render_boolean

render_boolean(raw: bool) -> str

Render a boolean as a check symbol or an empty string.

Parameters:

Name Type Description Default

raw

bool

Boolean value to render.

required

Returns:

Type Description
str

Configured check symbol if True, empty string if False.

Source code in oops/utils/render.py
def render_boolean(raw: bool) -> str:
    """Render a boolean as a check symbol or an empty string.

    Args:
        raw: Boolean value to render.

    Returns:
        Configured check symbol if True, empty string if False.
    """
    return config.check_symbol if raw else ""

render_maintainers

render_maintainers(manifest: dict) -> str

Render maintainer GitHub avatars as inline HTML image links.

Parameters:

Name Type Description Default

manifest

dict

Odoo manifest dict containing an optional "maintainers" list of GitHub usernames.

required

Returns:

Type Description
str

HTML string of circular avatar <img> elements wrapped in <a> tags,

str

or an empty string if no maintainers are listed.

Source code in oops/utils/render.py
def render_maintainers(manifest: dict) -> str:
    """Render maintainer GitHub avatars as inline HTML image links.

    Args:
        manifest: Odoo manifest dict containing an optional "maintainers" list of
            GitHub usernames.

    Returns:
        HTML string of circular avatar ``<img>`` elements wrapped in ``<a>`` tags,
        or an empty string if no maintainers are listed.
    """
    maintainers = manifest.get("maintainers") or []
    return " ".join(
        [
            f"<a href='https://github.com/{x}'>"
            f"<img src='https://github.com/{x}.png' width='32' height='32' style='border-radius:50%;' alt='{x}'/>"  # noqa: E501
            "</a>"
            for x in maintainers
        ]
    )

render_markdown_table

render_markdown_table(header: List[str], rows: List[List[str]]) -> str

Render a plain Markdown table from a header row and data rows.

Parameters:

Name Type Description Default

header

List[str]

List of column header strings.

required

rows

List[List[str]]

List of rows, where each row is a list of cell strings.

required

Returns:

Type Description
str

Markdown table string with a separator row after the header.

Source code in oops/utils/render.py
def render_markdown_table(header: List[str], rows: List[List[str]]) -> str:
    """Render a plain Markdown table from a header row and data rows.

    Args:
        header: List of column header strings.
        rows: List of rows, where each row is a list of cell strings.

    Returns:
        Markdown table string with a separator row after the header.
    """
    table = []
    rows = [header, ["---"] * len(header)] + rows
    for row in rows:
        table.append(" | ".join(row))
    return "\n".join(table)

render_table

render_table(rows: List[List[Any]], headers: Optional[List[str]] = None, index: bool = False) -> str

Render a list of rows as a GitHub-flavoured Markdown table.

Parameters:

Name Type Description Default

rows

List[List[Any]]

List of row data, where each row is a list of cell values.

required

headers

Optional[List[str]]

Optional column header labels.

None

index

bool

If True, prepend a numeric row index. Defaults to False.

False

Returns:

Type Description
str

Formatted Markdown table string.

Source code in oops/utils/render.py
def render_table(
    rows: List[List[Any]], headers: Optional[List[str]] = None, index: bool = False
) -> str:
    """Render a list of rows as a GitHub-flavoured Markdown table.

    Args:
        rows: List of row data, where each row is a list of cell values.
        headers: Optional column header labels.
        index: If True, prepend a numeric row index. Defaults to False.

    Returns:
        Formatted Markdown table string.
    """

    options = {}
    if index:
        options["showindex"] = True
    if headers:
        options["headers"] = headers

    return tabulate(rows, tablefmt="github", **options)

sanitize_cell

sanitize_cell(s: Any) -> str

Collapse internal whitespace in a table cell value.

Parameters:

Name Type Description Default

s

Any

Raw cell value string.

required

Returns:

Type Description
str

String with runs of whitespace replaced by a single space,

str

or an empty string if s is falsy.

Source code in oops/utils/render.py
def sanitize_cell(s: Any) -> str:
    """Collapse internal whitespace in a table cell value.

    Args:
        s: Raw cell value string.

    Returns:
        String with runs of whitespace replaced by a single space,
        or an empty string if s is falsy.
    """
    if not s:
        return ""
    s = " ".join(s.split())
    return s