Commit 297601d0 by Jonathan Piacenti

Simplify course URL discovery util.

parent 4ecf2286
......@@ -37,21 +37,9 @@ def course_id_from_url(url):
"""
if not url:
return None
deprecated = False
if '/' in url:
deprecated = True
# Ignore query string
url = url.split('?')[0]
if deprecated:
COURSE_REGEX = re.compile(r'^.*/courses/(?P<course_id>[^/]+/[^/]+/[^/]+)')
key_generator = SlashSeparatedCourseKey.from_deprecated_string
else:
COURSE_REGEX = re.compile(r'^.*?/courses/(?P<course_id>[a-zA-Z0-9_+\/:]+)')
key_generator = CourseKey.from_string
match = COURSE_REGEX.match(url)
if match is None:
return None
......@@ -60,7 +48,7 @@ def course_id_from_url(url):
return None
try:
course_key = key_generator(course_id)
return CourseKey.from_string(course_id)
except InvalidKeyError:
log.warning(
'unable to parse course_id "{}"'.format(course_id),
......@@ -68,8 +56,6 @@ def course_id_from_url(url):
)
return None
return course_key
class RequestMock(RequestFactory):
"""
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment