Source

milton / middleware / PageMiddleware.py

from logging import getLogger

from milton.models import Page
from milton.views import view_page

logger = getLogger(__name__)

class PageMiddleware(object):
    def process_request(self, request):
        path = request.path_info
        page = None
        
        # Look for a Page that matches; pass on failure.
        try:
            logger.debug("PageMiddleware: Looking for a page for %s" % (path,))
            page = Page.published.get(url=path)
        except Page.DoesNotExist, e:
            return None
        
        logger.debug("PageMiddleware: Found for a page for %s" % (path,))
        return view_page(request, path)