changeset 19:ef4155f8c234

For issue #5, add an untested (!) WSGI script. I'll test & refine this later when the site gets deployed.
author Brian Neal <bgneal@gmail.com>
date Mon, 31 Oct 2011 20:46:03 -0500
parents 71f2beb03789
children 7fce0720f89b
files bns_website/apache/bns.wsgi
diffstat 1 files changed, 50 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bns_website/apache/bns.wsgi	Mon Oct 31 20:46:03 2011 -0500
@@ -0,0 +1,50 @@
+import os
+import sys
+
+OFFLINE = False
+
+here = os.path.dirname(__file__)
+website = os.path.dirname(here)
+project = os.path.dirname(website)
+third_party_apps = os.path.join(project, '3rdparty')
+eggs = os.path.join(project, 'eggs')
+
+sys.path.extend([project, website, third_party_apps])
+
+os.environ['PYTHON_EGG_CACHE'] = eggs
+
+
+def offline_handler(environ, start_response):
+    """
+    This handler is run when the site is in maintenance mode.
+    It either displays a brief outage message, or, if a template
+    file exists, it reads the file and returns its contents.
+
+    """
+    wsgi_dir = os.path.dirname(__file__)
+    sys.path.append(wsgi_dir)
+
+    offline_file = os.path.abspath(
+            os.path.join(wsgi_dir, '..', 'templates', 'offline.html'))
+    if os.path.exists(offline_file):
+        response_headers = [('Content-type','text/html')]
+        response = open(offline_file).read()
+    else:
+        response_headers = [('Content-type','text/plain')]
+        response = ('Brave New Surf website maintenance in progress; '
+            'please check back soon.')
+
+    if environ['REQUEST_METHOD'] == 'GET':
+        status = '503 Service Unavailable'
+    else:
+        status = '405 Method Not Allowed'
+    start_response(status, response_headers)
+    return [response]
+
+
+if not OFFLINE:
+   os.environ['DJANGO_SETTINGS_MODULE'] = 'bns_website.settings.production'
+   import django.core.handlers.wsgi
+   application = django.core.handlers.wsgi.WSGIHandler()
+else:
+   application = offline_handler