Fix failing geoip searching on the homepage for unauthenticated users

This commit is contained in:
Michael Hall 2018-09-04 21:46:55 -04:00
parent e647984e4a
commit d8e9f70793

View file

@ -77,11 +77,12 @@ def home(request, *args, **kwards):
else:
city = sorted(nearby_cities, key=lambda city: location.city_distance_from(ll, city))[0]
if request.user.profile.city is None:
if request.user.is_authenticated and request.user.profile.city is None:
profile = request.user.profile
profile.city = city
profile.save()
except:
except Exception as err:
print("City lookup failed", err)
raise Exception('City lookup filed')
else:
raise Exception('Geocoder result has no latlng')