make PaidCourseRegistration mode aware

This commit is contained in:
Jason Bau
2013-08-20 13:20:06 -07:00
committed by Diana Huang
parent 6f3e83b86c
commit 5fbb12cb61
6 changed files with 55 additions and 10 deletions

View File

@@ -51,3 +51,18 @@ class CourseMode(models.Model):
if not modes:
modes = [cls.DEFAULT_MODE]
return modes
@classmethod
def mode_for_course(cls, course_id, mode_slug):
"""
Returns the mode for the course corresponding to mode_slug.
If this particular mode is not set for the course, returns None
"""
modes = cls.modes_for_course(course_id)
matched = filter(lambda m: m.slug == mode_slug, modes)
if matched:
return matched[0]
else:
return None

View File

@@ -60,3 +60,6 @@ class CourseModeModelTest(TestCase):
modes = CourseMode.modes_for_course(self.course_id)
self.assertEqual(modes, set_modes)
self.assertEqual(mode1, CourseMode.mode_for_course(self.course_id, u'honor'))
self.assertEqual(mode2, CourseMode.mode_for_course(self.course_id, u'verified'))
self.assertIsNone(CourseMode.mode_for_course(self.course_id, 'DNE'))