Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions coderedcms/models/page_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1797,15 +1797,13 @@ def to_geojson(self):
}

def save(self, *args, **kwargs):
if self.auto_update_latlng and GoogleApiSettings.for_site(
Site.objects.get(is_default_site=True)
).google_maps_api_key:
if self.auto_update_latlng:
try:
g = geocoder.google(self.address, key=GoogleApiSettings.for_site(
Site.objects.get(is_default_site=True)
).google_maps_api_key)
self.latitude = g.latlng[0]
self.longitude = g.latlng[1]
api_key = GoogleApiSettings.for_site(self.get_site()).google_maps_api_key
if api_key:
g = geocoder.google(self.address, key=api_key)
self.latitude = g.latlng[0]
self.longitude = g.latlng[1]
except TypeError:
# Raised if google denied the request
pass
Expand All @@ -1814,9 +1812,7 @@ def save(self, *args, **kwargs):

def get_context(self, request, *args, **kwargs):
context = super().get_context(request)
context['google_api_key'] = GoogleApiSettings.for_site(
Site.objects.get(is_default_site=True)
).google_maps_api_key
context['google_api_key'] = GoogleApiSettings.for_site(self.get_site()).google_maps_api_key
return context


Expand Down Expand Up @@ -1908,7 +1904,5 @@ def serve_geojson(self, request, *args, **kwargs):

def get_context(self, request, *args, **kwargs):
context = super().get_context(request)
context['google_api_key'] = GoogleApiSettings.for_site(
Site.objects.get(is_default_site=True)
).google_maps_api_key
context['google_api_key'] = GoogleApiSettings.for_site(self.get_site()).google_maps_api_key
return context