mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2026-05-09 15:35:46 -04:00
Use address keys only if city is found
This commit is contained in:
@@ -157,12 +157,7 @@ def extractIsoCode(user, data):
|
|||||||
for key in keys:
|
for key in keys:
|
||||||
if key.find("ISO") != -1:
|
if key.find("ISO") != -1:
|
||||||
iso_code = data['address'][key]
|
iso_code = data['address'][key]
|
||||||
if 'county' in keys:
|
|
||||||
town_city_or_county = data['address']['county']
|
|
||||||
if 'town' in keys:
|
|
||||||
town_city_or_county = data['address']['town']
|
|
||||||
if 'city' in keys:
|
|
||||||
town_city_or_county = data['address']['city']
|
|
||||||
if not iso_code:
|
if not iso_code:
|
||||||
return {"error": "No region found"}
|
return {"error": "No region found"}
|
||||||
|
|
||||||
@@ -174,9 +169,15 @@ def extractIsoCode(user, data):
|
|||||||
country_code = iso_code[:2]
|
country_code = iso_code[:2]
|
||||||
|
|
||||||
if region:
|
if region:
|
||||||
if town_city_or_county:
|
if 'city' in keys:
|
||||||
display_name = f"{town_city_or_county}, {region.name}, {country_code}"
|
city = City.objects.filter(name__contains=data['address']['city'], region=region).first()
|
||||||
city = City.objects.filter(name__contains=town_city_or_county, region=region).first()
|
if 'county' in keys and not city:
|
||||||
|
city = City.objects.filter(name__contains=data['address']['county'], region=region).first()
|
||||||
|
if 'town' in keys and not city:
|
||||||
|
city = City.objects.filter(name__contains=data['address']['town'], region=region).first()
|
||||||
|
|
||||||
|
if city:
|
||||||
|
display_name = f"{city.name}, {region.name}, {country_code}"
|
||||||
visited_city = VisitedCity.objects.filter(city=city, user=user).first()
|
visited_city = VisitedCity.objects.filter(city=city, user=user).first()
|
||||||
|
|
||||||
if visited_region:
|
if visited_region:
|
||||||
|
|||||||
Reference in New Issue
Block a user