Skip to content

Commit

Permalink
feat: add python native APIs from forum v2
Browse files Browse the repository at this point in the history
- migrate following native APIs i.e. get_user_course_stats, update_users_in_course
from forum v2 to edx-platform
  • Loading branch information
Muhammad Faraz Maqsood committed Oct 2, 2024
1 parent f6974be commit 596a6fd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,17 +81,21 @@ def get_course_user_stats(course_key: CourseKey, params: Optional[Dict] = None)
"""
if params is None:
params = {}
url = f"{settings.PREFIX}/users/{course_key}/stats"
return perform_request(
'get',
url,
params,
metric_action='user.course_stats',
metric_tags=[
f"course_key:{course_key}",
"function:get_course_user_stats",
],
)
if is_forum_v2_enabled(course_key):
course_stats = forum_api.get_user_course_stats(str(course_key), **params)
else:
url = f"{settings.PREFIX}/users/{course_key}/stats"
course_stats = perform_request(
'get',
url,
params,
metric_action='user.course_stats',
metric_tags=[
f"course_key:{course_key}",
"function:get_course_user_stats",
],
)
return course_stats


@function_trace("update_course_users_stats")
Expand All @@ -105,13 +109,17 @@ def update_course_users_stats(course_key: CourseKey) -> Dict:
Returns:
dict: data returned by API. Contains count of users updated.
"""
url = f"{settings.PREFIX}/users/{course_key}/update_stats"
return perform_request(
'post',
url,
metric_action='user.update_course_stats',
metric_tags=[
f"course_key:{course_key}",
"function:update_course_users_stats",
],
)
if is_forum_v2_enabled(course_key):
course_stats = forum_api.update_users_in_course(str(course_key))
else:
url = f"{settings.PREFIX}/users/{course_key}/update_stats"
course_stats = perform_request(
'post',
url,
metric_action='user.update_course_stats',
metric_tags=[
f"course_key:{course_key}",
"function:update_course_users_stats",
],
)
return course_stats
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"""
import logging

from opaque_keys.edx.keys import CourseKey

from . import models, settings, utils
from forum import api as forum_api
from lms.djangoapps.discussion.toggles import is_forum_v2_enabled
Expand Down

0 comments on commit 596a6fd

Please sign in to comment.