Added new Course List API.
This commit is contained in:
committed by
J. Cliff Dyer
parent
1b8349994e
commit
29b6ccf5e4
@@ -302,10 +302,6 @@ def _has_access_course_desc(user, action, course):
|
||||
"""
|
||||
Can see if can enroll, but also if can load it: if user enrolled in a course and now
|
||||
it's past the enrollment period, they should still see it.
|
||||
|
||||
TODO (vshnayder): This means that courses with limited enrollment periods will not appear
|
||||
to non-staff visitors after the enrollment period is over. If this is not what we want, will
|
||||
need to change this logic.
|
||||
"""
|
||||
# VS[compat] -- this setting should go away once all courses have
|
||||
# properly configured enrollment_start times (if course should be
|
||||
|
||||
@@ -44,21 +44,6 @@ from opaque_keys.edx.keys import UsageKey
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_request_for_thread():
|
||||
"""Walk up the stack, return the nearest first argument named "request"."""
|
||||
frame = None
|
||||
try:
|
||||
for f in inspect.stack()[1:]:
|
||||
frame = f[0]
|
||||
code = frame.f_code
|
||||
if code.co_varnames[:1] == ("request",):
|
||||
return frame.f_locals["request"]
|
||||
elif code.co_varnames[:2] == ("self", "request",):
|
||||
return frame.f_locals["request"]
|
||||
finally:
|
||||
del frame
|
||||
|
||||
|
||||
def get_course(course_id, depth=0):
|
||||
"""
|
||||
Given a course id, return the corresponding course descriptor.
|
||||
@@ -178,7 +163,7 @@ def get_course_university_about_section(course): # pylint: disable=invalid-name
|
||||
return course.display_org_with_default
|
||||
|
||||
|
||||
def get_course_about_section(course, section_key):
|
||||
def get_course_about_section(request, course, section_key):
|
||||
"""
|
||||
This returns the snippet of html to be rendered on the course about page,
|
||||
given the key for the section.
|
||||
@@ -206,17 +191,30 @@ def get_course_about_section(course, section_key):
|
||||
# markup. This can change without effecting this interface when we find a
|
||||
# good format for defining so many snippets of text/html.
|
||||
|
||||
# TODO: Remove number, instructors from this list
|
||||
if section_key in ['short_description', 'description', 'key_dates', 'video',
|
||||
'course_staff_short', 'course_staff_extended',
|
||||
'requirements', 'syllabus', 'textbook', 'faq', 'more_info',
|
||||
'number', 'instructors', 'overview',
|
||||
'effort', 'end_date', 'prerequisites', 'ocw_links']:
|
||||
# TODO: Remove number, instructors from this set
|
||||
html_sections = {
|
||||
'short_description',
|
||||
'description',
|
||||
'key_dates',
|
||||
'video',
|
||||
'course_staff_short',
|
||||
'course_staff_extended',
|
||||
'requirements',
|
||||
'syllabus',
|
||||
'textbook',
|
||||
'faq',
|
||||
'more_info',
|
||||
'number',
|
||||
'instructors',
|
||||
'overview',
|
||||
'effort',
|
||||
'end_date',
|
||||
'prerequisites',
|
||||
'ocw_links'
|
||||
}
|
||||
|
||||
if section_key in html_sections:
|
||||
try:
|
||||
|
||||
request = get_request_for_thread()
|
||||
|
||||
loc = course.location.replace(category='about', name=section_key)
|
||||
|
||||
# Use an empty cache
|
||||
|
||||
@@ -198,12 +198,10 @@ class CoursesRenderTest(ModuleStoreTestCase):
|
||||
course_info = get_course_info_section(self.request, self.course, 'handouts')
|
||||
self.assertIn("this module is temporarily unavailable", course_info)
|
||||
|
||||
@mock.patch('courseware.courses.get_request_for_thread')
|
||||
def test_get_course_about_section_render(self, mock_get_request):
|
||||
mock_get_request.return_value = self.request
|
||||
def test_get_course_about_section_render(self):
|
||||
|
||||
# Test render works okay
|
||||
course_about = get_course_about_section(self.course, 'short_description')
|
||||
course_about = get_course_about_section(self.request, self.course, 'short_description')
|
||||
self.assertEqual(course_about, "A course about toys.")
|
||||
|
||||
# Test when render raises an exception
|
||||
@@ -211,7 +209,7 @@ class CoursesRenderTest(ModuleStoreTestCase):
|
||||
mock_module_render.return_value = mock.MagicMock(
|
||||
render=mock.Mock(side_effect=Exception('Render failed!'))
|
||||
)
|
||||
course_about = get_course_about_section(self.course, 'short_description')
|
||||
course_about = get_course_about_section(self.request, self.course, 'short_description')
|
||||
self.assertIn("this module is temporarily unavailable", course_about)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user