feat: add location restrictions to recommendations (#31728)

VAN-1293

Co-authored-by: Syed Sajjad  Hussain Shah <syed.sajjad@H7FKF7K6XD.local>
This commit is contained in:
Syed Sajjad Hussain Shah
2023-02-16 15:39:47 +05:00
committed by GitHub
parent 83f6e560b7
commit 23db2c8a7a
2 changed files with 14 additions and 2 deletions

View File

@@ -2,6 +2,7 @@
import logging
from django.conf import settings
from ipware.ip import get_client_ip
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from edx_rest_framework_extensions.auth.session.authentication import (
SessionAuthenticationAllowInactiveUser,
@@ -15,6 +16,7 @@ from rest_framework.views import APIView
from common.djangoapps.student.models import CourseEnrollment
from common.djangoapps.student.toggles import show_fallback_recommendations
from common.djangoapps.track import segment
from openedx.core.djangoapps.geoinfo.api import country_code_from_ip
from openedx.core.djangoapps.programs.utils import (
ProgramProgressMeter,
get_certificates,
@@ -438,7 +440,11 @@ class CourseRecommendationApiView(APIView):
user_id, is_control, fallback_recommendations
)
filtered_courses = filter_recommended_courses(request.user, course_keys, recommendation_count=5)
ip_address = get_client_ip(request)[0]
user_country_code = country_code_from_ip(ip_address).upper()
filtered_courses = filter_recommended_courses(
request.user, course_keys, user_country_code=user_country_code, recommendation_count=5
)
if not filtered_courses:
return self._general_recommendations_response(
user_id, is_control, fallback_recommendations

View File

@@ -4,6 +4,7 @@ Views for Course Recommendations in Learner Home
import logging
from django.conf import settings
from ipware.ip import get_client_ip
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
from edx_rest_framework_extensions.auth.session.authentication import (
SessionAuthenticationAllowInactiveUser,
@@ -15,6 +16,7 @@ from rest_framework.views import APIView
from common.djangoapps.student.toggles import show_fallback_recommendations
from common.djangoapps.track import segment
from openedx.core.djangoapps.geoinfo.api import country_code_from_ip
from lms.djangoapps.learner_home.recommendations.serializers import (
CourseRecommendationSerializer,
)
@@ -67,7 +69,11 @@ class CourseRecommendationApiView(APIView):
if is_control or is_control is None or not course_keys:
return self._general_recommendations_response(user_id, is_control, fallback_recommendations)
filtered_courses = filter_recommended_courses(request.user, course_keys, recommendation_count=5)
ip_address = get_client_ip(request)[0]
user_country_code = country_code_from_ip(ip_address).upper()
filtered_courses = filter_recommended_courses(
request.user, course_keys, user_country_code=user_country_code, recommendation_count=5
)
# If no courses are left after filtering already enrolled courses from
# the list of amplitude recommendations, show general recommendations
# to the user.