Filter queryset by publish status.

  If project=True, we also apply a project exclusive filter

def by_address(queryset, address='', project=False):
  """
  Filter queryset by publish status.

  If project=True, we also apply a project exclusive filter
  """
  if address:
    address = json.loads(address)
    if u'address_components' in address:
      q_objs = []

      """
      Caribbean filter
      """
      if len(address[u'address_components']):
        if address[u'address_components'][0]['long_name'] == 'Caribbean':
          queryset = queryset.filter(
            SQ(address_components=helpers.whoosh_raw(u"{}-{}".format('Jamaica', 'country').strip())) |
            SQ(address_components=helpers.whoosh_raw(u"{}-{}".format('Haiti', 'country').strip())) |
            SQ(address_components=helpers.whoosh_raw(u"{}-{}".format('Saint Lucia', 'country').strip())) |
            SQ(address_components=helpers.whoosh_raw(u"{}-{}".format('Suriname', 'country').strip())) |
            SQ(address_components=helpers.whoosh_raw(u"{}-{}".format('Trinidad & Tobago', 'country').strip()))
          )

          return queryset

        for component in address[u'address_components']:
          q_obj = SQ()
          test = ''

          for component_type in component[u'types']:
            type_string = helpers.whoosh_raw(u"{}-{}".format(component[u'long_name'], component_type).strip())
            q_obj.add(SQ(address_components=type_string), SQ.OR)

          q_objs.append(q_obj)

        # Filter all address components
        for obj in q_objs:
          queryset = queryset.filter(obj)
      else: # remote projects
        if project:
          queryset = queryset.filter(can_be_done_remotely=1)
  return queryset