1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #35092 -- Exposed extra fields for GeoIP2.country() and GeoIP2.city() responses.

This commit is contained in:
Nick Pope
2024-01-10 11:09:44 +00:00
committed by GitHub
parent 9b02ad91ea
commit f50184a84b
4 changed files with 52 additions and 17 deletions

View File

@@ -203,18 +203,23 @@ class GeoIP2:
response = self._city.city(enc_query)
region = response.subdivisions[0] if response.subdivisions else None
return {
"accuracy_radius": response.location.accuracy_radius,
"city": response.city.name,
"continent_code": response.continent.code,
"continent_name": response.continent.name,
"country_code": response.country.iso_code,
"country_name": response.country.name,
"dma_code": response.location.metro_code,
"is_in_european_union": response.country.is_in_european_union,
"latitude": response.location.latitude,
"longitude": response.location.longitude,
"metro_code": response.location.metro_code,
"postal_code": response.postal.code,
"region": region.iso_code if region else None,
"region_code": region.iso_code if region else None,
"region_name": region.name if region else None,
"time_zone": response.location.time_zone,
# Kept for backward compatibility.
"dma_code": response.location.metro_code,
"region": region.iso_code if region else None,
}
def country_code(self, query):
@@ -235,8 +240,11 @@ class GeoIP2:
enc_query = self._check_query(query, city_or_country=True)
response = self._country_or_city(enc_query)
return {
"continent_code": response.continent.code,
"continent_name": response.continent.name,
"country_code": response.country.iso_code,
"country_name": response.country.name,
"is_in_european_union": response.country.is_in_european_union,
}
def coords(self, query, ordering=("longitude", "latitude")):