Skip to content

Commit

Permalink
monitoring: resolve 2-letter codes to 3-letter codes
Browse files Browse the repository at this point in the history
  • Loading branch information
cezio committed May 8, 2018
1 parent 0dcca88 commit f0366b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 8 additions & 0 deletions geonode/contrib/monitoring/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

import user_agents
from ipware import get_client_ip
import pycountry
from multi_email_field.forms import MultiEmailField

from geonode.utils import parse_datetime
Expand Down Expand Up @@ -457,6 +458,10 @@ def from_geonode(cls, service, request, response):
if client_loc:
lat, lon = client_loc['latitude'], client_loc['longitude'],
country = client_loc.get('country_code3') or client_loc['country_code']
if len(country) == 2:
_c = pycountry.countries.get(alpha_2=country)
country = _c.alpha_3

region = client_loc['region']
city = client_loc['city']

Expand Down Expand Up @@ -518,6 +523,9 @@ def from_geoserver(cls, service, request_data, received=None):
if client_loc:
lat, lon = client_loc['latitude'], client_loc['longitude'],
country = client_loc.get('country_code3') or client_loc['country_code']
if len(country) == 2:
_c = pycountry.countries.get(alpha_2=country)
country = _c.alpha_3
region = client_loc['region']
city = client_loc['city']

Expand Down
9 changes: 7 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,13 +161,19 @@ tablib<=0.12.1 # (0.12.1 in our ppa)
timeout-decorator==0.4.0 # TODO
typing<=3.6.4 # python-typing (3.6.4 in our ppa)

# required by monitoring
psutil # (3.4.2 in ppa)
django-cors-headers<=2.2.0 # python-django-cors-headers (2.2.0 in our ppa)
django-cuser==2017.3.16 # python-django-cuser (2017.3.16 in our ppa)
django-multi-email-field<=0.5.1 # python-django-multi-email-field (0.5.1 in our ppa)
# WeasyPrint
user-agents # python-user-agents (1.1.0 in our ppa)
xmljson # python-xmljson (0.1.9 in our ppa)
geoip2==2.8.0
django-ipware<2.2
# no version here, use latest one with fresh data
pycountry


#production
uWSGI==2.0.17
Expand All @@ -191,5 +197,4 @@ pytest-bdd==2.20.0
pytest-splinter==1.8.5
pytest-django==3.1.2
setuptools==39.0.1
geoip2==2.8.0
django-ipware<2.2

0 comments on commit f0366b2

Please sign in to comment.