Fixed geocoding validity

This commit is contained in:
Antonio 2018-03-16 16:01:00 +01:00
parent d66804b93d
commit e78063ae75

View File

@ -48,18 +48,31 @@ class TomTomGeocoder(Traceable):
latitude = position[ENTRY_LAT]
return [longitude, latitude]
def _validate_input(self, searchtext, city=None, state_province=None,
country=None):
if searchtext and searchtext.strip():
return True
elif city:
return True
elif state_province:
return True
return False
@qps_retry(qps=5)
def geocode(self, searchtext, city=None, state_province=None,
country=None):
if searchtext and searchtext.strip():
address = [normalize(searchtext)]
if city:
address.append(normalize(city))
if state_province:
address.append(normalize(state_province))
else:
if not self._validate_input(searchtext, city, state_province, country):
return []
address = []
if searchtext and searchtext.strip():
address.append(normalize(searchtext))
if city:
address.append(normalize(city))
if state_province:
address.append(normalize(state_province))
uri = self._uri(searchtext=', '.join(address), countries=country)
try: