예제 #1
0
 def process_response(self, request, response):
     if response.status_code != 404:
         return response # No need to check for a flatpage for non-404 responses.
     try: 
         return page(request, request.path_info)
     # Return the original response if any errors happened. Because this
     # is a middleware, we can't assume the errors will be caught elsewhere.
     except Http404:
         return response
     except:
         if settings.DEBUG:
             raise
         return response
예제 #2
0
 def process_response(self, request, response):
     if response.status_code != 404:
         return response  # No need to check for a page for non-404 responses.
     try:
         return page(request, request.path_info)
     # Return the original response if any errors happened. Because this
     # is a middleware, we can't assume the errors will be caught elsewhere.
     except Http404:
         return response
     except:
         if settings.DEBUG:
             raise
         return response
예제 #3
0
    def process_response(self, request, response):
        if response.status_code != 404:
            # Pass anything but a 404 straight through.
            return response

        try:
            # Try the page view.
            return page(request, request.path_info)
        except Http404:
            # If the page view 404s, return the ORIGINAL 404 response.
            return response
        except:
            # If anything else happened, something is wrong with the page view.
            # Return the original (404) response, unless we're in DEBUG.
            if settings.DEBUG:
                raise
            return response
예제 #4
0
파일: middleware.py 프로젝트: sjl/stoat
    def process_response(self, request, response):
        if response.status_code != 404:
            # Pass anything but a 404 straight through.
            return response

        try:
            # Try the page view.
            return page(request, request.path_info)
        except Http404:
            # If the page view 404s, return the ORIGINAL 404 response.
            return response
        except:
            # If anything else happened, something is wrong with the page view.
            # Return the original (404) response, unless we're in DEBUG.
            if settings.DEBUG:
                raise
            return response
예제 #5
0
    def test_page(self):
        self.assertEqual(views.page(1), "/apis/v2/page/1")

        views.page = MagicMock(return_value="/apis/v1/page/1")
        self.assertEqual(views.page(1), "/apis/v2/page/1")    # fails
예제 #6
0
 def test_page(self):
     res = views.page(1)
     self.assertEqual(res, "/apis/v1/page/1")