Пример #1
0
def use_default(variable, default):
    """Return either the variable value, or a default value, depending on value of global variable
  use_default_values"""
    if use_default_values:
        return default
    else:
        return value(variable)
def yes_no_unknown(var_name, condition, unknown="Unknown", placeholder=0):
    """Return 'unknown' if the value is None rather than False. Helper for PDF filling with
  yesnomaybe fields"""
    if condition:
        return value(var_name)
    elif condition is None:
        return unknown
    else:
        return placeholder
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 ''
Пример #4
0
def gather_fields(field_list, exclude=[], skip_undefinable = True, undefinable=None):
  """Trigger the gathering of a list of fields (as strings) in Docassemble. Optionally, skip any fields undefinable in this interview session."""
  if skip_undefinable:
    if undefinable is None:
      undefinable = undefinable_fields(field_list)
    exclude.extend(undefinable)
  for field in field_list:
    if not field in exclude:
      if isinstance(value(field),Individual):
        value(field + '.name.first')
      elif isinstance(value(field),Address):
        value(field + '.address')
      else:
        value(field) # use Docassemble function to require the definition of the field
  
  return True
def trigger_user_questions(interview_metadata_dict, question_order=None):
    """There may be a more elegant way to handle this."""
    if not question_order:
        question_order = [
            'guardian',
            'caregiver',
            'guardian_ad_litem',
            'attorney',
            'translator',
            'witness',
            'spouse',
            'user',
            'user.address',
            'user.email',
        ]
    for field in question_order:
        if field in interview_metadata_dict.get('built_in_fields_used', []):
            if isinstance(value(field), Individual):
                value(field + '.name.first')
            elif isinstance(value(field), Address):
                value(field + '.address')
            else:
                value(field)
Пример #6
0
def optional(field: str):
    """Returns the value of the field, if it exists, otherwise empty"""
    return DAEmpty() if not defined(field) else value(field)
Пример #7
0
def pdf_fields_code(fields):
  temp_fields = dict()
  for field in fields:
    temp_fields[field] = value(field)
  return temp_fields
Пример #8
0
def set_attribute_to_value(field_list, object_type, attribute, target_value=DAEmpty()):
  """If any item in the list matches object_type, set the specified attribute to DAEmpty() or other value desired"""
  for field in field_list:
    if defined(field) and isinstance(value(field), object_type):
      define(field + '.' + attribute, target_value)
Пример #9
0
def adjust(item, length=None):
    try:
        val = value(item)
        return str(val).ljust(length or 20)
    except:
        return " " * (length or 20)
Пример #10
0
def exists(item):
    try:
        val = value(item)
        return len(str(val).strip()) > 0
    except:
        return False