forked from CGM_Public/pretix_original
Fix crash on failed geocoding
This commit is contained in:
@@ -23,6 +23,7 @@ class GeoCodeView(LoginRequiredMixin, View):
|
|||||||
}, status=200)
|
}, status=200)
|
||||||
|
|
||||||
gs = GlobalSettingsObject()
|
gs = GlobalSettingsObject()
|
||||||
|
try:
|
||||||
if gs.settings.opencagedata_apikey:
|
if gs.settings.opencagedata_apikey:
|
||||||
res = self._use_opencage(q)
|
res = self._use_opencage(q)
|
||||||
elif gs.settings.mapquest_apikey:
|
elif gs.settings.mapquest_apikey:
|
||||||
@@ -32,6 +33,12 @@ class GeoCodeView(LoginRequiredMixin, View):
|
|||||||
'success': False,
|
'success': False,
|
||||||
'results': []
|
'results': []
|
||||||
}, status=200)
|
}, status=200)
|
||||||
|
except IOError:
|
||||||
|
logger.exception("Geocoding failed")
|
||||||
|
return JsonResponse({
|
||||||
|
'success': False,
|
||||||
|
'results': []
|
||||||
|
}, status=200)
|
||||||
|
|
||||||
cache.set('geocode:{}'.format(q), res, timeout=3600 * 6)
|
cache.set('geocode:{}'.format(q), res, timeout=3600 * 6)
|
||||||
return JsonResponse({
|
return JsonResponse({
|
||||||
@@ -42,20 +49,12 @@ class GeoCodeView(LoginRequiredMixin, View):
|
|||||||
def _use_opencage(self, q):
|
def _use_opencage(self, q):
|
||||||
gs = GlobalSettingsObject()
|
gs = GlobalSettingsObject()
|
||||||
|
|
||||||
try:
|
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
'https://api.opencagedata.com/geocode/v1/json?q={}&key={}'.format(
|
'https://api.opencagedata.com/geocode/v1/json?q={}&key={}'.format(
|
||||||
quote(q), gs.settings.opencagedata_apikey
|
quote(q), gs.settings.opencagedata_apikey
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except IOError:
|
|
||||||
logger.exception("Geocoding failed")
|
|
||||||
return JsonResponse({
|
|
||||||
'success': False,
|
|
||||||
'results': []
|
|
||||||
}, status=200)
|
|
||||||
else:
|
|
||||||
d = r.json()
|
d = r.json()
|
||||||
res = [
|
res = [
|
||||||
{
|
{
|
||||||
@@ -69,20 +68,12 @@ class GeoCodeView(LoginRequiredMixin, View):
|
|||||||
def _use_mapquest(self, q):
|
def _use_mapquest(self, q):
|
||||||
gs = GlobalSettingsObject()
|
gs = GlobalSettingsObject()
|
||||||
|
|
||||||
try:
|
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
'https://www.mapquestapi.com/geocoding/v1/address?location={}&key={}'.format(
|
'https://www.mapquestapi.com/geocoding/v1/address?location={}&key={}'.format(
|
||||||
quote(q), gs.settings.mapquest_apikey
|
quote(q), gs.settings.mapquest_apikey
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
except IOError:
|
|
||||||
logger.exception("Geocoding failed")
|
|
||||||
return JsonResponse({
|
|
||||||
'success': False,
|
|
||||||
'results': []
|
|
||||||
}, status=200)
|
|
||||||
else:
|
|
||||||
d = r.json()
|
d = r.json()
|
||||||
res = [
|
res = [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user