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
, orfff
for blacksize
- used to control the fontawesome size (without thefa-
prefix). Valid values include2xs
,xs
, the default ofsm
,md
,lg
,xl
,2x1
, and the pythonNone
, which defaults tomd
.fa_class
- let's you specify the fontawesome class, needed for any icon that isn't the default class offa-solid
, likefa-brands
, orfa-regular
andfa-light
.aria_hidden
- if True, addsaria-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 presseddown_action
- the variable name of an event to be executed on the server if the thumbs down is pressedreview_action
- the variable name of an event to be execute on the server when someone submits their text reviewthumbs_display
- text displayed to user describing the thumbsreview_display
- text displayed to user describing the text inputsubmit_review_button
- text on the button to submit their text reviewpost_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 aDAFile
orDAStaticFile
with the image of a checkboxunchecked_value
- opposite meaning ofchecked_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 buttonimage
: the name of a fontawesome icon to display on the buttonurl
: the name of the page to link toprivilege
: 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 divcustom_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 checkother_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 checkother_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.