Skip to main content

ALToolbox.addenda

__all__

myTable Objects

class myTable()

Utility class for creating table representations from DAList objects for addenda.

This class processes DAList objects containing 'Individual' or 'Thing' objects and converts them into structured table format suitable for document addenda. It handles data sanitization and formatting for display purposes.

__init__

def __init__(tblData, tblTitle, tblHeader)

Initialize a table from DAList data with title and headers.

Arguments

  • tblData - A DAList object containing Individual or Thing objects.
  • tblTitle str - The title for the table.
  • tblHeader - The column headers for the table.

myTextList Objects

class myTextList()

Utility class for managing text fields that may exceed form space limits.

This class handles text content that might be too long to fit in the main form by truncating it at a specified limit and storing the overflow text for use in addenda or continuation pages.

__init__

def __init__(text, limit, title)

Initialize text processing with truncation limits.

Arguments

  • text str - The text content to process and potentially truncate.
  • limit int - The character limit for the main form field.
  • title str - The title or identifier for the text field.

g

def g(text, limit, title) -> None

Process text for addendum generation by truncating if needed and storing overflow.

Determines if the provided text exceeds the character limit and truncates it with an addendum notice if necessary. The original text is stored for inclusion in an addendum section if truncation occurs.

Arguments

  • text str - The text content to process for length.
  • limit int - The maximum character limit for the main text field.
  • title str - The title/label for this text field, used in the addendum.

Notes

Sets self.text_cutoff to the truncated text (with addendum notice if needed) and self.txtList to contain addendum data if truncation occurred.

Example

>>> text_handler = myTextList("Very long text...", 100, "Description")
>>> # If text > 100 chars, text_cutoff will end with " (See Addendum.)"

types

datetime

decimal

re

json

Any

TypeType

safe_json2

def safe_json2(the_object, level=0, is_key=False) -> Any

Convert Python objects to JSON-serializable format with enhanced date handling.

A revision of the safe_json function that converts complex Python objects into formats that can be safely serialized to JSON. Handles datetime objects by converting them to formatted date strings (MM/DD/YYYY format) rather than ISO strings.

Arguments

  • the_object - The Python object to convert to a JSON-serializable format.
  • level int, optional - Current recursion depth to prevent infinite loops. Defaults to 0.
  • is_key bool, optional - Whether this object is being used as a dictionary key. Defaults to False.

Returns

A JSON-serializable representation of the input object. Returns "None" for keys or None for values when objects cannot be serialized and recursion limit is exceeded.

Example

>>> import datetime
>>> obj = {"date": datetime.datetime(2023, 12, 25)}
>>> safe_json2(obj)
{"date": "12/25/2023"}

type_name

def type_name(the_object) -> str

Extract the class name from a Python object's type string representation.

Parses the string representation of an object's type to extract just the class name, removing the surrounding type syntax.

Arguments

  • the_object - Any Python object whose type name should be extracted.

Returns

  • str - The class name of the object, or the full type string if parsing fails.

Example

>>> type_name("hello")
'str'
>>> type_name([1, 2, 3])
'list'