mirror of
https://github.com/ansible/awx.git
synced 2026-05-08 01:47:35 -02:30
inherit rather than monkey patch
* Enable migration in progress page in ALL environments
This commit is contained in:
33
awx/wsgi.py
33
awx/wsgi.py
@@ -9,8 +9,7 @@ from awx import prepare_env, MODE
|
||||
prepare_env()
|
||||
|
||||
|
||||
from django.core.handlers.base import BaseHandler # NOQA
|
||||
from django.core.wsgi import get_wsgi_application # NOQA
|
||||
from django.core.wsgi import WSGIHandler # NOQA
|
||||
import django # NOQA
|
||||
from django.conf import settings # NOQA
|
||||
from django.urls import resolve # NOQA
|
||||
@@ -38,8 +37,8 @@ if MODE == 'production':
|
||||
|
||||
if django.__version__ != '1.11.7':
|
||||
raise RuntimeError("Django version other than 1.11.7 detected {}. \
|
||||
Monkey Patch to support short-circuit Django Middelware \
|
||||
is known to work for Django 1.11.7 and may not work with other, \
|
||||
Inherit from WSGIHandler to support short-circuit Django Middelware. \
|
||||
This is known to work for Django 1.11.7 and may not work with other, \
|
||||
even minor, versions.".format(django.__version__))
|
||||
|
||||
|
||||
@@ -48,20 +47,24 @@ if settings.MIDDLEWARE:
|
||||
The 'migration in progress' view feature short-circuits OLD Django \
|
||||
MIDDLEWARE_CLASSES behavior. With the new Django MIDDLEWARE beahvior \
|
||||
it's possible to short-ciruit the middleware onion through supported \
|
||||
middleware mechanisms. The monkey patch wrapper below should be removed.")
|
||||
middleware mechanisms. Further, from django.core.wsgi.get_wsgi_application() \
|
||||
should be called to get an instance of WSGIHandler().")
|
||||
|
||||
|
||||
def _wrapper_legacy_get_response(self, request):
|
||||
# short-circuit middleware
|
||||
if getattr(resolve(request.path), 'url_name', '') == 'migrations_notran':
|
||||
return self._get_response(request)
|
||||
# fall through to middle-ware
|
||||
else:
|
||||
return self._real_legacy_get_response(request)
|
||||
class AWXWSGIHandler(WSGIHandler):
|
||||
def _legacy_get_response(self, request):
|
||||
# short-circuit middleware
|
||||
if getattr(resolve(request.path), 'url_name', '') == 'migrations_notran':
|
||||
return self._get_response(request)
|
||||
# fall through to middle-ware
|
||||
else:
|
||||
return super(AWXWSGIHandler, self)._legacy_get_response(request)
|
||||
|
||||
|
||||
BaseHandler._real_legacy_get_response = BaseHandler._legacy_get_response
|
||||
BaseHandler._legacy_get_response = _wrapper_legacy_get_response
|
||||
|
||||
# Return the default Django WSGI application.
|
||||
def get_wsgi_application():
|
||||
django.setup(set_prefix=False)
|
||||
return AWXWSGIHandler()
|
||||
|
||||
|
||||
application = get_wsgi_application()
|
||||
|
||||
Reference in New Issue
Block a user