Skip to content

Commit

Permalink
refactor: [AXM-549] Use course keys instead ids
Browse files Browse the repository at this point in the history
  • Loading branch information
KyryloKireiev committed Oct 30, 2024
1 parent 4015aab commit e868888
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lms/djangoapps/mobile_api/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import datetime
import logging
from functools import cached_property
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Set

import pytz
from completion.exceptions import UnavailableCompletionData
Expand All @@ -20,6 +20,7 @@
from django.utils.decorators import method_decorator
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import UsageKey
from opaque_keys.edx.locator import CourseLocator
from rest_framework import generics, views
from rest_framework.decorators import api_view
from rest_framework.permissions import SAFE_METHODS
Expand Down Expand Up @@ -613,7 +614,7 @@ def _build_enrollments_status_dict(
self,
username: str,
active_status_date: datetime,
course_ids: List[str],
course_ids: Set[CourseLocator],
) -> List[Dict[str, bool]]:
"""
Builds list with dictionaries with user's enrolments statuses.
Expand All @@ -631,10 +632,10 @@ def _build_enrollments_status_dict(
]
enrollments_status = []
for user_enrollment in mobile_available:
course_id = str(user_enrollment.course_overview.id)
course_id = user_enrollment.course_overview.id
enrollments_status.append(
{
'course_id': course_id,
'course_id': str(course_id),
'course_name': user_enrollment.course_overview.display_name,
'recently_active': bool(
course_id in course_ids
Expand All @@ -648,16 +649,16 @@ def _build_enrollments_status_dict(
def _get_course_ids_where_user_has_completions(
username: str,
active_status_date: datetime,
) -> List[str]:
) -> Set[CourseLocator]:
"""
Gets course ids where user has completions.
Gets course keys where user has completions.
"""
context_keys = BlockCompletion.objects.filter(
user__username=username,
created__gte=active_status_date
).values_list('context_key', flat=True).distinct()

return [str(context_key) for context_key in context_keys]
return set(context_keys)


class UserCourseEnrollmentsV4Pagination(DefaultPagination):
Expand Down

0 comments on commit e868888

Please sign in to comment.