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.

Example​

For a legacy interview with household_members declared as a DAList of Individual objects, use addendum_table.tableList in the addendum template. The first list entry is omitted from the addendum; this helper recognizes base Individual/Thing types rather than AssemblyLine subclasses.

Input (interview YAML)

code: |
addendum_table = myTable(household_members, "Household members", ["Name"])

__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.

Example​

With a gathered text variable description, prepare the main form’s description_overflow.text_cutoff and the addendum’s description_overflow.txtList.

Input (interview YAML)

code: |
description_overflow = myTextList(description, 40, "Description")

__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​

With a gathered text variable description, prepare the main form’s description_overflow.text_cutoff and the addendum’s description_overflow.txtList. The object is an existing myTextList.

Input (interview YAML)

code: |
description_overflow.g(description, 40, "Description")

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​

With users[0].birthdate set to January 2, 1990, the value of serializable_answers is:

Input (interview YAML)

code: |
serializable_answers = safe_json2({"birthdate": users[0].birthdate})

Output

{'birthdate': '01/02/1990'}

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​

When inspecting a value while developing an interview, value_type is:

Input (interview YAML)

code: |
from docassemble.ALToolbox.addenda import type_name
value_type = type_name("Alex")

Output

str