]> git.openstreetmap.org Git - osqa.git/commitdiff
adding middleware that handles custom pages
authorjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 1 Aug 2011 10:21:46 +0000 (10:21 +0000)
committerjordan <jordan@0cfe37f9-358a-4d5e-be75-b63607b5c754>
Mon, 1 Aug 2011 10:21:46 +0000 (10:21 +0000)
git-svn-id: http://svn.osqa.net/svnroot/osqa/trunk@1141 0cfe37f9-358a-4d5e-be75-b63607b5c754

forum/middleware/custom_pages.py [new file with mode: 0644]
settings.py

diff --git a/forum/middleware/custom_pages.py b/forum/middleware/custom_pages.py
new file mode 100644 (file)
index 0000000..122793b
--- /dev/null
@@ -0,0 +1,20 @@
+from django.contrib.flatpages.views import flatpage
+from django.http import Http404
+from django.conf import settings
+
+from forum.views.meta import page
+
+class CustomPagesFallbackMiddleware(object):
+    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)
+        # 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
index 041f6ae286661c8b17afed686f4df556a44972aa..f42268b6accfb6700c2fcaa0cbf40e6647ecfb6b 100644 (file)
@@ -25,6 +25,7 @@ MIDDLEWARE_CLASSES = [
     'forum.middleware.request_utils.RequestUtils',
     'forum.middleware.cancel.CancelActionMiddleware',
     'forum.middleware.admin_messages.AdminMessagesMiddleware',
+    'forum.middleware.custom_pages.CustomPagesFallbackMiddleware',
     'django.middleware.transaction.TransactionMiddleware',
     'forum.middleware.django_cookies.CookiePostHandlerMiddleware',
 ]