Пример #1
0
def salute(person):
    greeting = ""
    if defined("person.preferred_salutation"):
        greeting += person.preferred_salutation + " " + person.name.last
    else:
        if defined("person.gender"):
            if person.gender.lower() == 'male':
                greeting += "Mr. " + person.name.last
            elif person.gender.lower() == 'female':
                greeting += "Ms. " + person.name.last
            else:
                greeting += str(person.name)
        else:
            greeting += str(person.name)
    return greeting
Пример #2
0
def sum_if_defined(*pargs):
    """Lets you add up the value of variables that are not in a list"""
    total = 0
    for source in pargs:
        if defined(source):
            total += value(source)
    return total
 def value_if_defined(self) -> Any:
     """
 Return the value of the field if it is defined, otherwise return an empty string.
 Addendum should never trigger docassemble's variable gathering.
 """
     if defined(self.field_name):
         return value(self.field_name)
     return ""
Пример #4
0
def greet(person):
    greeting = ""
    if defined('person.preferred_greeting'):
        greeting = person.preferred_greeting
    else:
        greeting = "Dear"
    greeting += " " + salute(person)
    return greeting
Пример #5
0
def sum_if_defined(*pargs):
    """
  Return sum of all variables as a comma-separated list. Must put variable names in quotes.
  """
    sum = 0
    for var in pargs:
        if defined(var):
            sum += value(var)
    return sum
Пример #6
0
def space(var_name, prefix=" ", suffix=""):
    """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."""
    if (var_name and isinstance(var_name, str)
            and re.search(r"[A-Za-z][A-Za-z0-9\_]*", var_name)
            and defined(var_name) and value(var_name)):
        return prefix + showifdef(var_name) + suffix
    else:
        return ""
 def defined_fields(self, style='overflow_only'):
     """
 Return a filtered list of just the defined fields.
 If the "style" is set to overflow_only, only return the overflow values.
 """
     if style == 'overflow_only':
         return [
             field for field in self.values() if len(field.overflow_value())
         ]
     else:
         return [
             field for field in self.values() if defined(field.field_name)
         ]
Пример #8
0
def docx_x_mark(var_name, var_eq=None):
    if defined(var_name) and value(var_name) == var_eq:
        return 'X'
    else:
        # two spaces is closer to the size of the X in Times New Roman. :shrug:
        return '  '