Skip to content

Commit

Permalink
Merge pull request #2609 from Eskimon/revert-geoip
Browse files Browse the repository at this point in the history
Revert geoip
  • Loading branch information
SpaceFox committed May 3, 2015
2 parents 39eb8f4 + 9dbbb2d commit 524c4cf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -45,7 +45,6 @@ install:
- sudo apt-get install texlive-xetex
- sudo apt-get install texlive-lang-french
- sudo apt-get install texlive-latex-extra
- sudo apt-get install libgeoip-dev

# Add fonts
- sudo wget -P /usr/share/fonts/truetype https://www.dropbox.com/s/ema28tjn52960mq/Merriweather.zip
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Expand Up @@ -13,7 +13,7 @@ django-munin==0.1.5
python-memcached==1.53
lxml==3.4.2
factory-boy==2.4.1
geoip==1.3.2
pygeoip==0.3.2
pillow==2.7.0
gitpython==0.3.6
https://github.com/zestedesavoir/Python-ZMarkdown/archive/2.6.0-zds.7.zip
Expand All @@ -26,4 +26,4 @@ django-filter==0.9.2
django-oauth-toolkit==0.7.2
drf-extensions==0.2.7
django-rest-swagger==0.2.9
django-cors-headers==1.0.0
django-cors-headers==1.0.0
40 changes: 25 additions & 15 deletions zds/member/models.py
@@ -1,27 +1,26 @@
# coding: utf-8

from datetime import datetime
import os

from hashlib import md5
from importlib import import_module

from django.conf import settings
from django.db import models
from hashlib import md5
from django.http import HttpRequest
from django.utils.http import urlquote
from django.contrib.sessions.models import Session
from django.contrib.auth import logout
import os

from django.contrib.auth.models import User
from django.contrib.gis.geoip import GeoIP
from django.contrib.sessions.models import Session
from django.core.urlresolvers import reverse
from django.db import models
from django.dispatch import receiver
from django.http import HttpRequest
from django.utils.http import urlquote

import pygeoip
from zds.article.models import Article
from zds.forum.models import Post, Topic
from zds.member.managers import ProfileManager
from zds.tutorial.models import Tutorial
from zds.utils.models import Alert
from importlib import import_module


class Profile(models.Model):
Expand Down Expand Up @@ -117,11 +116,22 @@ def get_city(self):
providers.
:return: The city and the country name of this profile.
"""
g = GeoIP()
geo = g.city(self.last_ip_address)
if geo is not None:
return u'{0}, {1}'.format(geo['city'], geo['country_name'])
return ''
# FIXME: this test to differentiate IPv4 and IPv6 addresses doesn't work, as IPv6 addresses may have length < 16
# Example: localhost ("::1"). Real test: IPv4 addresses contains dots, IPv6 addresses contains columns.
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}'.format(
geo['city'], geo['country_name'])

def get_avatar_url(self):
"""
Expand Down

0 comments on commit 524c4cf

Please sign in to comment.