Skip to content

Commit 416e054

Browse files
committed
Enable using MMDB files containing only countries
1 parent 617727c commit 416e054

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

user_sessions/templatetags/user_sessions.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,22 @@ def device(value):
107107

108108
@register.filter
109109
def city(value):
110-
location = geoip() and geoip().city(value)
110+
try:
111+
location = geoip() and geoip().city(value)
112+
except Exception:
113+
location = None
111114
if location and location['city']:
112115
return location['city']
113116
return None
114117

115118

116119
@register.filter
117120
def country(value):
118-
location = geoip() and geoip().country(value)
121+
try:
122+
location = geoip() and geoip().country(value)
123+
except Exception as e:
124+
warnings.warn(str(e), stacklevel=2)
125+
location = geoip() and geoip().city(value)
119126
if location and location['country_name']:
120127
return location['country_name']
121128
return None

0 commit comments

Comments
 (0)