Skip to content

Commit

Permalink
Upgrading ipware (#33804)
Browse files Browse the repository at this point in the history
* feat: Upgrade Python dependency django-ipware (#33805)
  • Loading branch information
awais786 authored Nov 29, 2023
1 parent 2b8f2a1 commit f852594
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
12 changes: 8 additions & 4 deletions openedx/core/djangoapps/geoinfo/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
import logging

from django.utils.deprecation import MiddlewareMixin
from ipware.ip import get_client_ip
from ipware.utils import is_public_ip
from python_ipware import IpWare

from .api import country_code_from_ip

Expand All @@ -30,13 +29,18 @@ def process_request(self, request):
Store country code in session.
"""
new_ip_address = get_client_ip(request)[0]
ipw = IpWare()
new_ip_address_obj, _ = ipw.get_client_ip(meta=request.META)

if new_ip_address_obj:
new_ip_address = format(new_ip_address_obj)

old_ip_address = request.session.get('ip_address', None)

if not new_ip_address and old_ip_address:
del request.session['ip_address']
del request.session['country_code']
elif new_ip_address != old_ip_address and is_public_ip(new_ip_address):
elif new_ip_address != old_ip_address and new_ip_address_obj.is_global:
country_code = country_code_from_ip(new_ip_address)
request.session['country_code'] = country_code
request.session['ip_address'] = new_ip_address
Expand Down
4 changes: 3 additions & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ django-filter==23.3
# edx-enterprise
# lti-consumer-xblock
# openedx-blockstore
django-ipware==5.0.2
django-ipware==6.0.0
# via
# -r requirements/edx/kernel.in
# edx-enterprise
Expand Down Expand Up @@ -925,6 +925,8 @@ python-dateutil==2.8.2
# olxcleaner
# ora2
# xblock
python-ipware==2.0.0
# via django-ipware
python-memcached==1.59
# via -r requirements/edx/paver.txt
python-slugify==8.0.1
Expand Down
7 changes: 6 additions & 1 deletion requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ django-filter==23.3
# edx-enterprise
# lti-consumer-xblock
# openedx-blockstore
django-ipware==5.0.2
django-ipware==6.0.0
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
Expand Down Expand Up @@ -1640,6 +1640,11 @@ python-dateutil==2.8.2
# olxcleaner
# ora2
# xblock
python-ipware==2.0.0
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
# django-ipware
python-memcached==1.59
# via
# -r requirements/edx/doc.txt
Expand Down
6 changes: 5 additions & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ django-filter==23.3
# edx-enterprise
# lti-consumer-xblock
# openedx-blockstore
django-ipware==5.0.2
django-ipware==6.0.0
# via
# -r requirements/edx/base.txt
# edx-enterprise
Expand Down Expand Up @@ -1102,6 +1102,10 @@ python-dateutil==2.8.2
# olxcleaner
# ora2
# xblock
python-ipware==2.0.0
# via
# -r requirements/edx/base.txt
# django-ipware
python-memcached==1.59
# via -r requirements/edx/base.txt
python-slugify==8.0.1
Expand Down
6 changes: 5 additions & 1 deletion requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ django-filter==23.3
# edx-enterprise
# lti-consumer-xblock
# openedx-blockstore
django-ipware==5.0.2
django-ipware==6.0.0
# via
# -r requirements/edx/base.txt
# edx-enterprise
Expand Down Expand Up @@ -1231,6 +1231,10 @@ python-dateutil==2.8.2
# olxcleaner
# ora2
# xblock
python-ipware==2.0.0
# via
# -r requirements/edx/base.txt
# django-ipware
python-memcached==1.59
# via -r requirements/edx/base.txt
python-slugify==8.0.1
Expand Down

0 comments on commit f852594

Please sign in to comment.