forked from CGM_Public/pretix_original
Fix crash on failed geocoding
This commit is contained in:
@@ -23,11 +23,18 @@ class GeoCodeView(LoginRequiredMixin, View):
|
|||||||
}, status=200)
|
}, status=200)
|
||||||
|
|
||||||
gs = GlobalSettingsObject()
|
gs = GlobalSettingsObject()
|
||||||
if gs.settings.opencagedata_apikey:
|
try:
|
||||||
res = self._use_opencage(q)
|
if gs.settings.opencagedata_apikey:
|
||||||
elif gs.settings.mapquest_apikey:
|
res = self._use_opencage(q)
|
||||||
res = self._use_mapquest(q)
|
elif gs.settings.mapquest_apikey:
|
||||||
else:
|
res = self._use_mapquest(q)
|
||||||
|
else:
|
||||||
|
return JsonResponse({
|
||||||
|
'success': False,
|
||||||
|
'results': []
|
||||||
|
}, status=200)
|
||||||
|
except IOError:
|
||||||
|
logger.exception("Geocoding failed")
|
||||||
return JsonResponse({
|
return JsonResponse({
|
||||||
'success': False,
|
'success': False,
|
||||||
'results': []
|
'results': []
|
||||||
@@ -42,21 +49,13 @@ 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()
|
)
|
||||||
except IOError:
|
r.raise_for_status()
|
||||||
logger.exception("Geocoding failed")
|
d = r.json()
|
||||||
return JsonResponse({
|
|
||||||
'success': False,
|
|
||||||
'results': []
|
|
||||||
}, status=200)
|
|
||||||
else:
|
|
||||||
d = r.json()
|
|
||||||
res = [
|
res = [
|
||||||
{
|
{
|
||||||
'formatted': r['formatted'],
|
'formatted': r['formatted'],
|
||||||
@@ -69,21 +68,13 @@ 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()
|
)
|
||||||
except IOError:
|
r.raise_for_status()
|
||||||
logger.exception("Geocoding failed")
|
d = r.json()
|
||||||
return JsonResponse({
|
|
||||||
'success': False,
|
|
||||||
'results': []
|
|
||||||
}, status=200)
|
|
||||||
else:
|
|
||||||
d = r.json()
|
|
||||||
res = [
|
res = [
|
||||||
{
|
{
|
||||||
'formatted': q,
|
'formatted': q,
|
||||||
|
|||||||
Reference in New Issue
Block a user