Skip to main content

ALToolbox.misc

thousands​

Return a whole number formatted with thousands separator. Optionally, format with 2 decimal points (for a PDF form with the currency symbol already present in the form)

If show_decimals, will call int(num), truncating the decimals instead of rounding to the closest int.

tel​

Format a phone number so you can click on it to open in your phone dialer

fa_icon​

Display a fontawesome icon inline.

Docassemble allows you to display an icon from fontawesome, but it does not provide control over the size or color of the icon. This function gives you more control over the icon that is inserted.

Arguments:

  • icon - a string representing a fontawesome icon. The icon needs to be in the free library.
  • color - can be any Bootstrap color variable. For example: primary, secondary, warning
  • color_css - allows you to use a CSS code to represent the color, e.g., blue, or fff for black
  • size - used to control the fontawesome size (without the fa- prefix). Valid values include 2xs, xs, the default of sm, md, lg, xl, 2x1, and the python None, which defaults to md.
  • fa_class - let's you specify the fontawesome class, needed for any icon that isn't the default class of fa-solid, like fa-brands, or fa-regular and fa-light.
  • aria_hidden - if True, adds aria-hidden="true" to the icon, which is the default

Returns:

HTML for a font-awesome icon of the specified size and color.

space​

If the value as a string is defined, return it prefixed/suffixed. Defaults to prefix of a space. Helps build a sentence with less cruft. Equivalent to SPACE function in HotDocs.

yes_no_unknown​

Return 'unknown' if the value is None rather than False. Helper for PDF filling with yesnomaybe fields

number_to_letter​

Returns a capital letter representing ordinal position. E.g., 1=A, 2=B, etc. Appends letters once you reach 26 in a way compatible with Excel/Google Sheets column naming conventions. 27=AA, 28=AB...

collapse_template​

Insert HTML for a Bootstrap "collapse" div.

Optionally, you can specify a custom icon to override the defaults:

The default icons are "right caret" which displays when the text is collapsed (closed_icon) and "down caret" which displays when the text is open (open_icon).

tabbed_templates_html​

Provided a list of templates, create Bootstrap v 4.5 tabs with the subject as the tab label.

review_widget​

A widget that allows people to give a quick review (thumbs up and down, with an optional text component) in the middle of an interview without triggering a page reload.

If review_action is provided, once you press either of the thumbs, a text input screen with a submit button appears, and once the text review is submitted (or after the thumbs, if no review_action was provided), a final "thank you" message is displayed.

Arguments:

  • up_action - the variable name of an event to be executed on the server if the thumbs up is pressed
  • down_action - the variable name of an event to be executed on the server if the thumbs down is pressed
  • review_action - the variable name of an event to be execute on the server when someone submits their text review
  • thumbs_display - text displayed to user describing the thumbs
  • review_display - text displayed to user describing the text input
  • submit_review_button - text on the button to submit their text review
  • post_review_display - text displayed to user after review is submitted

Returns:

the HTML string of the widget

sum_if_defined​

Lets you add up the value of variables that are not in a list

add_records​

List demo interviews in the current package to be run from the landing page

output_checkbox​

Generate a conditional checkbox for docx templates

Arguments:

  • checked_value - defaults to [X] but can be set to any string or even a DAFile or DAStaticFile with the image of a checkbox
  • unchecked_value - opposite meaning of checked_value and defaults to [ ]

nice_county_name​

If the county name contains the word "County", which Google Address Autocomplete does by default, remove it.

button_array​

Create a grid of da-buttons from a dictionary of links and icons

This uses the same CSS classes to mimic the look and feel of Docassemble's buttons field type, but doesn't have the limits of that particular input method. This is meant to appear on any page of an interview in the subquestion area.

Optionally, you can limit access to paricular buttons by specifying a privilege or a list of privileges.

Arguments:

  • button_list - a dictionary of ButtonDicts (or plain dictionaries) with the following keys:
    • name: the text to display on the button
    • image: the name of a fontawesome icon to display on the button
    • url: the name of the page to link to
    • privilege: optional, the name of a Docassemble privilege that the user must have to see the button. Can be a list or a single string.
  • custom_container_class - optional, a string of additional CSS classes to add to the container div
  • custom_link_class - optional, a string of additional CSS classes to add to each link

Returns:

HTML for a grid of buttons

none_to_empty​

If the value is None or "None", return a DAEmpty value. Otherwise return the value.

This is useful for filling in a template and to prevent the word None from appearing in the output. For example, when handling a radio button that is not required and left unanswered.

A DAEmpty value appears as an empty string in the output. You can also safely transform it or use any method on it without raising an error.

Arguments:

  • val - the value to check

Returns:

a DAEmpty if the value is None, otherwise the value

option_or_other​

If the variable is set to 'Other', return the value of the 'other' variable. Otherwise return the value of the variable.

This is useful for filling in a template and to prevent the word 'Other' from appearing in the output.

Arguments:

  • variable_name - the name of the variable to check
  • other_variable_name - the name of the variable to return if the value of the first variable is 'Other'

Returns:

the value of the variable if it is not 'Other', otherwise the value of the other variable

true_values_with_other​

Return a list of values that are True, with the value of the 'other' variable appended to the end of the list.

This is useful for filling in a template and to prevent the word 'Other' from appearing in the output.

Arguments:

  • variable - the dictionary of variables to check
  • other_variable_name - the name of the variable (as a string) to return if the value of the first variable is 'Other'

Returns:

a list of values that are True, with the value of the 'other' variable appended to the end of the list.

include_a_year​

Validates whether the input text contains at least one 4-digit sequence that occurs within a range of ~ 200 years, indicating a valid "year" for an event that should be reported on most court forms, like a birthdate or a moving date.

Returns True if found, otherwise raises a DAValidationError.