Skip to content

Commit

Permalink
corrige la geolocalisation des adresses IPv6
Browse files Browse the repository at this point in the history
  • Loading branch information
firm1 committed Jun 3, 2014
1 parent 450276e commit f339ac2
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions zds/member/models.py
Expand Up @@ -95,11 +95,17 @@ def get_absolute_url(self):

def get_city(self):
"""return physical adress by geolocalisation."""
gic = pygeoip.GeoIP(
os.path.join(
settings.GEOIP_PATH,
'GeoLiteCity.dat'))
geo = gic.record_by_addr(self.last_ip_address)
if len(self.last_ip_address) <= 16:
gic = pygeoip.GeoIP(
os.path.join(
settings.GEOIP_PATH,
'GeoLiteCity.dat'))
else:
gic = pygeoip.GeoIP(
os.path.join(
settings.GEOIP_PATH,
'GeoLiteCityv6.dat'))
geo = gic.record_by_addr(self.last_ip_address)

return u'{0} ({1}) : {2}'.format(
geo['city'], geo['postal_code'], geo['country_name'])
Expand Down

0 comments on commit f339ac2

Please sign in to comment.