Exemple #1
0
 def __call__(self, combiner) -> bool:
     """
     Returns True if the field is being updated and the value is not blank.
     """
     if self.field not in combiner.data:
         return False
     return is_not_blank(combiner.data[self.field])
 def get_area_code(self, post_code):
     """
     Get area code from a postcode
     :param post_code: Post Code from an address
     :return: An area code based on the format states list
     """
     if is_not_blank(post_code):
         for zip_prefix, area_code, _area_name in self.zip_states:
             if post_code.startswith(zip_prefix):
                 return area_code
     return None
 def fix_address_postcode(self, company):
     """
     Fix address postcode formatting the postcode into an expected format if possible
     :param company: Company record
     """
     if is_not_blank(company.address_postcode):
         log_message = f'Updating address postcode from "{company.address_postcode}"'
         company.address_postcode = self.format_postcode(
             company.address_postcode)
         logger.info(
             f'{log_message} to address postcode "{company.address_postcode}"'
         )
         company.save(force_update=True)
         return True
     return False
 def fix_registered_address_postcode(self, company):
     """
     Fix registered address postcode formatting the postcode into an expected format if possible
      :param company: company record
     """
     if is_not_blank(company.registered_address_postcode):
         log_message = (
             f'Updating registered postcode from "{company.registered_address_postcode}"'
         )
         company.registered_address_postcode = self.format_postcode(
             company.registered_address_postcode, )
         logger.info(
             f'{log_message} to registered postcode ',
             f'"{company.registered_address_postcode}"',
         )
         company.save(force_update=True)
         return True
     return False
Exemple #5
0
 def __call__(self, combiner) -> bool:
     """Test whether any of the fields are not blank."""
     return any(is_not_blank(combiner[field]) for field in self._fields)
def test_is_not_blank(value, blank):
    """Tests is_not_blank() for various values."""
    assert is_not_blank(value) == blank