Skip to content

Commit 1dc445c

Browse files
committed
Also work with GeoIP2 country database
1 parent 2b7fd9b commit 1dc445c

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

docs/release-notes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
Release Notes
22
=============
33

4+
1.5.2
5+
-----
6+
* Also work with GeoIP2 country database
7+
48
1.5.1
59
-----
610
* Updated documentation for GeoIP2 library

user_sessions/templatetags/user_sessions.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,16 @@ def location(value):
9898
"""
9999
try:
100100
location = geoip() and geoip().city(value)
101-
if location and location['country_name']:
102-
if location['city']:
103-
return '{}, {}'.format(location['city'], location['country_name'])
104-
return location['country_name']
105101
except Exception as e:
106-
warnings.warn(str(e))
102+
try:
103+
location = geoip() and geoip().country(value)
104+
except Exception as e:
105+
warnings.warn(str(e))
106+
location = None
107+
if location and location['country_name']:
108+
if 'city' in location:
109+
return '{}, {}'.format(location['city'], location['country_name'])
110+
return location['country_name']
107111
return None
108112

109113

0 commit comments

Comments
 (0)