1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
From: Tapio Rantala <tapio.rantala@iki.fi>
Date: Sun, 11 Oct 2015 11:43:20 +1100
Subject: Use Debian GeoIP database path as default
Default to Debian standard path for GeoIP directory and for GeoIP city
file. Avoids the need to declare them in each project.
.
This is a Debian specific patch.
Bug-Debian: http://bugs.debian.org/645094
Forwarded: not-needed
Patch-Name: 06_use_debian_geoip_database_as_default.diff
---
django/contrib/gis/geoip2/base.py | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/django/contrib/gis/geoip2/base.py b/django/contrib/gis/geoip2/base.py
index 6b35a8acdc42..ff6141bdcc5b 100644
--- a/django/contrib/gis/geoip2/base.py
+++ b/django/contrib/gis/geoip2/base.py
@@ -53,6 +53,7 @@ class GeoIP2:
to where the city or country data files (*.mmdb) are located.
Assumes that both the city and country data sets are located in
this directory; overrides the GEOIP_PATH setting.
+ If neither is set, defaults to '/usr/share/GeoIP'.
* cache: The cache settings when opening up the GeoIP datasets. May be
an integer in (0, 1, 2, 4, 8) corresponding to the MODE_AUTO,
@@ -62,9 +63,11 @@ class GeoIP2:
* country: The name of the GeoIP country data file. Defaults to
'GeoLite2-Country.mmdb'; overrides the GEOIP_COUNTRY setting.
+ If neither is set, defaults to 'GeoIP.dat'.
* city: The name of the GeoIP city data file. Defaults to
'GeoLite2-City.mmdb'; overrides the GEOIP_CITY setting.
+ If neither is set, defaults to 'GeoIPCity.dat'.
"""
# Checking the given cache option.
if cache in self.cache_options:
@@ -73,7 +76,7 @@ class GeoIP2:
raise GeoIP2Exception('Invalid GeoIP caching option: %s' % cache)
# Getting the GeoIP data path.
- path = path or GEOIP_SETTINGS['GEOIP_PATH']
+ path = path or GEOIP_SETTINGS.get('GEOIP_PATH', '/usr/share/GeoIP')
if not path:
raise GeoIP2Exception('GeoIP path must be provided via parameter or the GEOIP_PATH setting.')
@@ -82,12 +85,12 @@ class GeoIP2:
# Constructing the GeoIP database filenames using the settings
# dictionary. If the database files for the GeoLite country
# and/or city datasets exist, then try to open them.
- country_db = path / (country or GEOIP_SETTINGS['GEOIP_COUNTRY'])
+ country_db = path / (country or GEOIP_SETTINGS.get('GEOIP_COUNTRY', 'GeoIP.dat'))
if country_db.is_file():
self._country = geoip2.database.Reader(str(country_db), mode=cache)
self._country_file = country_db
- city_db = path / (city or GEOIP_SETTINGS['GEOIP_CITY'])
+ city_db = path / (city or GEOIP_SETTINGS.get('GEOIP_CITY', 'GeoIPCity.dat'))
if city_db.is_file():
self._city = geoip2.database.Reader(str(city_db), mode=cache)
self._city_file = city_db
|