Mercurial > public > bravenewsurf
comparison bns_website/apache/bns.wsgi @ 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 | |
children | 6f68f6800843 |
comparison
equal
deleted
inserted
replaced
16:71f2beb03789 | 19:ef4155f8c234 |
---|---|
1 import os | |
2 import sys | |
3 | |
4 OFFLINE = False | |
5 | |
6 here = os.path.dirname(__file__) | |
7 website = os.path.dirname(here) | |
8 project = os.path.dirname(website) | |
9 third_party_apps = os.path.join(project, '3rdparty') | |
10 eggs = os.path.join(project, 'eggs') | |
11 | |
12 sys.path.extend([project, website, third_party_apps]) | |
13 | |
14 os.environ['PYTHON_EGG_CACHE'] = eggs | |
15 | |
16 | |
17 def offline_handler(environ, start_response): | |
18 """ | |
19 This handler is run when the site is in maintenance mode. | |
20 It either displays a brief outage message, or, if a template | |
21 file exists, it reads the file and returns its contents. | |
22 | |
23 """ | |
24 wsgi_dir = os.path.dirname(__file__) | |
25 sys.path.append(wsgi_dir) | |
26 | |
27 offline_file = os.path.abspath( | |
28 os.path.join(wsgi_dir, '..', 'templates', 'offline.html')) | |
29 if os.path.exists(offline_file): | |
30 response_headers = [('Content-type','text/html')] | |
31 response = open(offline_file).read() | |
32 else: | |
33 response_headers = [('Content-type','text/plain')] | |
34 response = ('Brave New Surf website maintenance in progress; ' | |
35 'please check back soon.') | |
36 | |
37 if environ['REQUEST_METHOD'] == 'GET': | |
38 status = '503 Service Unavailable' | |
39 else: | |
40 status = '405 Method Not Allowed' | |
41 start_response(status, response_headers) | |
42 return [response] | |
43 | |
44 | |
45 if not OFFLINE: | |
46 os.environ['DJANGO_SETTINGS_MODULE'] = 'bns_website.settings.production' | |
47 import django.core.handlers.wsgi | |
48 application = django.core.handlers.wsgi.WSGIHandler() | |
49 else: | |
50 application = offline_handler |