Skip to content

Commit ba9e110

Browse files
committed
Added new functions to figures.sites to support query abstractions
- Added `course_enrollments_for_course` - Added `student_modules_for_course_enrollment` This is to support the course progress pipeline performance improvement code restructuring. The purpose of adding these functions is to move forward with using `figures.sites` as the source of platform data. To note, there are a number of places in the code that do not follow this. As we rework Figures, we will refactor code to use `figures.sites` instead of directly querying the platform models. Note the function name change from the existing functions. We are moving away from using the `get_` prefix for the site functions.
1 parent 2ad0f40 commit ba9e110

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

figures/sites.py

+32
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ class CourseNotInSiteError(CrossSiteResourceError):
3939
pass
4040

4141

42+
class UnlinkedCourseError(Exception):
43+
"""Raise when we need to fail if we can't get the site for a course
44+
45+
This will happen in multisite mode if the course is not linked to the site.
46+
In Tahoe Hawthorn, we use the Appsembler fork of `edx-organizations` to map
47+
courses to sites. For community and standalone deployments, we don't expect
48+
courses to map to sites, so we just return the app instance's default site.
49+
50+
* This is new to support enrollment metrics rework (May 2020)
51+
* We need to evaluate if we want to make sites.get_site_for_course` to
52+
raise this automatically. But first we need to make sure we have test
53+
coverage to make sure we don't introduce new bugs
54+
"""
55+
pass
56+
57+
4258
def site_to_id(site):
4359
"""
4460
Helper to cast site or site id to id
@@ -181,3 +197,19 @@ def get_student_modules_for_course_in_site(site, course_id):
181197
def get_student_modules_for_site(site):
182198
course_ids = get_course_keys_for_site(site)
183199
return StudentModule.objects.filter(course_id__in=course_ids)
200+
201+
202+
def course_enrollments_for_course(course_id):
203+
"""Return a queryset of all `CourseEnrollment` records for a course
204+
205+
Relies on the fact that course_ids are globally unique
206+
"""
207+
return CourseEnrollment.objects.filter(course_id=as_course_key(course_id))
208+
209+
210+
def student_modules_for_course_enrollment(ce):
211+
"""Return a queryset of all `StudentModule` records for a `CourseEnrollment`1
212+
213+
Relies on the fact that course_ids are globally unique
214+
"""
215+
return StudentModule.objects.filter(student=ce.user, course_id=ce.course_id)

0 commit comments

Comments
 (0)