Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: 0 additions & 4 deletions requirements/common_constraints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,3 @@
elasticsearch<7.14.0

# django-simple-history>3.0.0 adds indexing and causes a lot of migrations to be affected

# tox>4.0.0 isn't yet compatible with many tox plugins, causing CI failures in almost all repos.
# Details can be found in this discussion: https://github.com/tox-dev/tox/discussions/1810
tox<4.0.0
Comment thread
mariajgrimaldi marked this conversation as resolved.
Outdated
4 changes: 3 additions & 1 deletion requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ django-filter==23.3
# edx-enterprise
# lti-consumer-xblock
# openedx-blockstore
django-ipware==5.0.1
django-ipware==6.0.0
# via
# -r requirements/edx/kernel.in
# edx-enterprise
Expand Down Expand Up @@ -930,6 +930,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
8 changes: 6 additions & 2 deletions requirements/edx/development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ django-filter==23.3
# edx-enterprise
# lti-consumer-xblock
# openedx-blockstore
django-ipware==5.0.1
django-ipware==6.0.0
# via
# -r requirements/edx/doc.txt
# -r requirements/edx/testing.txt
Expand Down Expand Up @@ -1651,6 +1651,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 Expand Up @@ -2053,7 +2058,6 @@ tomlkit==0.12.1
# snowflake-connector-python
tox==3.28.0
# via
# -c requirements/edx/../common_constraints.txt
# -r requirements/edx/testing.txt
# tox-battery
tox-battery==0.6.2
Expand Down
6 changes: 5 additions & 1 deletion requirements/edx/doc.txt
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ django-filter==23.3
# edx-enterprise
# lti-consumer-xblock
# openedx-blockstore
django-ipware==5.0.1
django-ipware==6.0.0
# via
# -r requirements/edx/base.txt
# edx-enterprise
Expand Down Expand Up @@ -1110,6 +1110,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
7 changes: 5 additions & 2 deletions requirements/edx/testing.txt
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ django-filter==23.3
# edx-enterprise
# lti-consumer-xblock
# openedx-blockstore
django-ipware==5.0.1
django-ipware==6.0.0
# via
# -r requirements/edx/base.txt
# edx-enterprise
Expand Down Expand Up @@ -1243,6 +1243,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 Expand Up @@ -1514,7 +1518,6 @@ tomlkit==0.12.1
# snowflake-connector-python
tox==3.28.0
# via
# -c requirements/edx/../common_constraints.txt
# -r requirements/edx/testing.in
# tox-battery
tox-battery==0.6.2
Expand Down