middleware.py 1.18 KB
Newer Older
1
"""
2
This file implements the Middleware support for the Open edX platform.
3 4 5 6 7 8
A microsite enables the following features:

1) Mapping of sub-domain name to a 'brand', e.g. foo-university.edx.org
2) Present a landing page with a listing of courses that are specific to the 'brand'
3) Ability to swap out some branding elements in the website
"""
9
from microsite_configuration import microsite
10 11


12
class MicrositeMiddleware(object):
13 14 15 16 17 18 19 20 21 22
    """
    Middleware class which will bind configuration information regarding 'microsites' on a per request basis.
    The actual configuration information is taken from Django settings information
    """

    def process_request(self, request):
        """
        Middleware entry point on every request processing. This will associate a request's domain name
        with a 'University' and any corresponding microsite configuration information
        """
23
        microsite.clear()
24 25 26

        domain = request.META.get('HTTP_HOST', None)

27
        microsite.set_by_domain(domain)
28 29 30 31 32 33 34

        return None

    def process_response(self, request, response):
        """
        Middleware entry point for request completion.
        """
35
        microsite.clear()
36
        return response