forked from sclorg/django-ex
-
Notifications
You must be signed in to change notification settings - Fork 9
/
wsgi.py
52 lines (39 loc) · 1.7 KB
/
wsgi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""
WSGI config for project project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/
"""
import logging
import os
import platform
from django.core.wsgi import get_wsgi_application
from django.core.management import execute_from_command_line
class NoHealthFilter(logging.Filter):
def filter(self, record):
return record.getMessage().find('GET /health') == -1
# disable logging of the Openshift health checks
if __name__ != "__main__":
gunicorn_logger = logging.getLogger("gunicorn.access")
gunicorn_logger.addFilter(NoHealthFilter())
is_local = False
# check if the app is running on OpenShift
if not os.environ.get('OPENSHIFT_BUILD_NAMESPACE', False):
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "edivorce.settings.local")
is_local = True
else:
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "edivorce.settings.openshift")
if os.environ.get('POD_INIT_COMPLETE', "") != "True":
# gunicorn starts multiple threads and runs wsgi.py once for each thread. We only want
# these commands to run ONCE.
os.environ["POD_INIT_COMPLETE"] = "True"
# compress the static assets
execute_from_command_line(['manage.py', 'compress', '--force'])
question_fixture_path = '/opt/app-root/src/edivorce/fixtures/Question.json'
platform_name = platform.system()
if platform_name == "Windows":
question_fixture_path = os.path.realpath("./edivorce/fixtures/Question.json")
# load the Question fixture
if not is_local:
execute_from_command_line(['manage.py', 'loaddata', question_fixture_path])
application = get_wsgi_application()