Files
edx-platform/lms/djangoapps/courseware/middleware.py
2016-05-03 09:02:45 -04:00

25 lines
709 B
Python

"""
Middleware for the courseware app
"""
from django.shortcuts import redirect
from django.core.urlresolvers import reverse
from courseware.courses import UserNotEnrolled
class RedirectUnenrolledMiddleware(object):
"""
Catch UserNotEnrolled errors thrown by `get_course_with_access` and redirect
users to the course about page
"""
def process_exception(self, _request, exception):
if isinstance(exception, UserNotEnrolled):
course_key = exception.course_key
return redirect(
reverse(
'courseware.views.views.course_about',
args=[course_key.to_deprecated_string()]
)
)