middleware.py 507 Bytes
Newer Older
1 2 3 4 5 6
"""
Middleware for the courseware app
"""

from django.shortcuts import redirect

7
from lms.djangoapps.courseware.exceptions import Redirect
8

9

10
class RedirectMiddleware(object):
11
    """
12
    Catch Redirect exceptions and redirect the user to the expected URL.
13
    """
stv committed
14
    def process_exception(self, _request, exception):
15 16 17 18 19
        """
        Catch Redirect exceptions and redirect the user to the expected URL.
        """
        if isinstance(exception, Redirect):
            return redirect(exception.url)