def mark_unfilled_fields_empty(interview_metadata_dict):
    """Sets the listed fields that are not yet defined to an empty string. Requires an interview metadata dictionary
  as input parameter. Aid for filling in a PDF. This will not set ALL fields in the interview empty;
  only ones mentiond in the specific metadata dict."""
    # There are two dictionaries in the interview-specific metadata that list fields
    # fields and built_in_fields used. Some older interviews may use `field_list`
    # We loop over each field and check if it's already defined in the Docassemble interview's namespace
    # If it isn't, we set it to an empty string.
    for field_dict in interview_metadata_dict[
            'field_list'] + interview_metadata_dict[
                'built_in_fields_used'] + interview_metadata_dict['fields']:
        try:
            field = field_dict[
                'variable']  # Our list of fields is a dictionary
        except:
            continue
        # Make sure we don't try to define a method
        # Also, don't set any signatures to DAEmpty
        # This will not work on a method call, other than the 3 we explicitly handle:
        # address.line_two(), address.on_one_line(), and address.block()
        # Empty strings will break this
        if field and not map_names(field).endswith(
                '.signature') and not '(' in map_names(field):
            if not defined(map_names(field)):
                define(map_names(field), '')  # set to an empty string
                #define(map_names(field), 'DAEmpty()') # set to special Docassemble empty object. Should work in DA > 1.1.4
        # Handle special case of an address that we skipped filling in on the form
        elif map_names(field).endswith('address.on_one_line()'):
            address_obj_name = map_names(field).partition('.on_one_line')[0]
            if not defined(
                    address_obj_name + '.address'
            ):  # here we're checking for an empty street address attribute
                # define(individual_name, '') # at this point this should be something like user.address
                try:
                    exec(address_obj_name + "= DAEmpty()")
                except:
                    pass
                # define(address_obj_name, DAEmpty())
        elif map_names(field).endswith('address.line_two()'):
            address_obj_name = map_names(field).partition('.line_two')[0]
            if not defined(address_obj_name + '.city'
                           ):  # We check for an undefined city attribute
                try:
                    exec(address_obj_name + "= DAEmpty()")
                except:
                    pass
        elif map_names(field).endswith('address.block()'):
            address_obj_name = map_names(field).partition('.block')[0]
            if not defined(address_obj_name + '.address'
                           ):  # We check for an undefined street address
                try:
                    exec(address_obj_name + "= DAEmpty()")
                except:
                    pass
def mark_unfilled_fields_empty(interview_metadata_dict):
    """Given an interview metadata dictionary, transform any un-filled fields into DAEmpty()"""
    for field_dict in interview_metadata_dict.get(
            'field_list', []) + interview_metadata_dict.get(
                'built_in_fields_used', []):
        try:
            field = field_dict[
                'variable']  # Our list of fields is a dictionary
        except:
            continue
        # Make sure we don't try to define a method
        # Also, don't set any signatures to DAEmpty
        if not map_names(field).endswith(
                '.signature') and not '(' in map_names(field):
            if not defined(map_names(field)):
                define(map_names(field),
                       '')  # set to special Docassemble empty object
                #define(map_names(field), DAEmpty()) # set to special Docassemble empty object
        # Handle special case of an address that we skipped filling in on the form
        elif map_names(field).endswith('address.on_one_line()'):
            individual_name = map_names(field).partition('.on_one_line')[0]
            if not defined(
                    individual_name + '.address'
            ):  # here we're checking for an empty street address attribute
                define(
                    individual_name, ''
                )  # at this point this should be something like user.address
        elif map_names(field).endswith('address.line_two()'):
            individual_name = map_names(field).partition('.line_two')[0]
            if not defined(individual_name + '.city'):
                define(individual_name, '')
Exemplo n.º 3
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)