From d3a02bc3e5fc56d2e491b7a95e83e97ce4f54554 Mon Sep 17 00:00:00 2001 From: Ayub-khan Date: Tue, 11 Feb 2020 12:45:54 +0500 Subject: [PATCH] BOM-1121 -Updated middleware setting to use use middleware insted of middleware_classes -github install of django-method-override fork to support new style middleware in django1.11 --- cms/envs/common.py | 2 +- cms/envs/devstack.py | 2 +- cms/envs/production.py | 2 +- common/djangoapps/third_party_auth/settings.py | 2 +- common/djangoapps/third_party_auth/tests/test_settings.py | 4 ++-- lms/envs/common.py | 2 +- lms/envs/devstack.py | 2 +- lms/envs/load_test.py | 2 +- lms/envs/production.py | 2 +- openedx/core/djangoapps/safe_sessions/testing.py | 2 +- requirements/constraints.txt | 3 --- requirements/edx/base.in | 1 - requirements/edx/base.txt | 2 +- requirements/edx/development.txt | 2 +- requirements/edx/github.in | 4 ++++ requirements/edx/testing.txt | 2 +- 16 files changed, 18 insertions(+), 18 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 967c442a28..6961b292bd 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -566,7 +566,7 @@ XQUEUE_INTERFACE = { ################################# Middleware ################################### -MIDDLEWARE_CLASSES = [ +MIDDLEWARE = [ 'openedx.core.lib.x_forwarded_for.middleware.XForwardedForMiddleware', 'crum.CurrentRequestUserMiddleware', diff --git a/cms/envs/devstack.py b/cms/envs/devstack.py index cb5c4b410f..1e73c03f97 100644 --- a/cms/envs/devstack.py +++ b/cms/envs/devstack.py @@ -72,7 +72,7 @@ CELERY_ALWAYS_EAGER = True INSTALLED_APPS += ['debug_toolbar'] -MIDDLEWARE_CLASSES.append('debug_toolbar.middleware.DebugToolbarMiddleware') +MIDDLEWARE.append('debug_toolbar.middleware.DebugToolbarMiddleware') INTERNAL_IPS = ('127.0.0.1',) DEBUG_TOOLBAR_PANELS = ( diff --git a/cms/envs/production.py b/cms/envs/production.py index 1860cdac98..23a09c6ed7 100644 --- a/cms/envs/production.py +++ b/cms/envs/production.py @@ -589,7 +589,7 @@ PARENTAL_CONSENT_AGE_LIMIT = ENV_TOKENS.get( ########################## Extra middleware classes ####################### # Allow extra middleware classes to be added to the app through configuration. -MIDDLEWARE_CLASSES.extend(ENV_TOKENS.get('EXTRA_MIDDLEWARE_CLASSES', [])) +MIDDLEWARE.extend(ENV_TOKENS.get('EXTRA_MIDDLEWARE_CLASSES', [])) ########################## Settings for Completion API ##################### diff --git a/common/djangoapps/third_party_auth/settings.py b/common/djangoapps/third_party_auth/settings.py index f43c188952..0f6a4536c3 100644 --- a/common/djangoapps/third_party_auth/settings.py +++ b/common/djangoapps/third_party_auth/settings.py @@ -23,7 +23,7 @@ def apply_settings(django_settings): django_settings.FIELDS_STORED_IN_SESSION = ['auth_entry', 'next'] # Inject exception middleware to make redirects fire. - django_settings.MIDDLEWARE_CLASSES.extend( + django_settings.MIDDLEWARE.extend( ['third_party_auth.middleware.ExceptionMiddleware'] ) diff --git a/common/djangoapps/third_party_auth/tests/test_settings.py b/common/djangoapps/third_party_auth/tests/test_settings.py index 9c1158e611..495a64cbda 100644 --- a/common/djangoapps/third_party_auth/tests/test_settings.py +++ b/common/djangoapps/third_party_auth/tests/test_settings.py @@ -14,7 +14,7 @@ _ORIGINAL_TEMPLATE_CONTEXT_PROCESSORS = ['first_template_context_preprocessor'] _SETTINGS_MAP = { 'AUTHENTICATION_BACKENDS': _ORIGINAL_AUTHENTICATION_BACKENDS, 'INSTALLED_APPS': _ORIGINAL_INSTALLED_APPS, - 'MIDDLEWARE_CLASSES': _ORIGINAL_MIDDLEWARE_CLASSES, + 'MIDDLEWARE': _ORIGINAL_MIDDLEWARE_CLASSES, 'TEMPLATES': [{ 'OPTIONS': { 'context_processors': _ORIGINAL_TEMPLATE_CONTEXT_PROCESSORS @@ -37,7 +37,7 @@ class SettingsUnitTest(testutil.TestCase): def test_apply_settings_adds_exception_middleware(self): settings.apply_settings(self.settings) - self.assertIn('third_party_auth.middleware.ExceptionMiddleware', self.settings.MIDDLEWARE_CLASSES) + self.assertIn('third_party_auth.middleware.ExceptionMiddleware', self.settings.MIDDLEWARE) def test_apply_settings_adds_fields_stored_in_session(self): settings.apply_settings(self.settings) diff --git a/lms/envs/common.py b/lms/envs/common.py index 25f1fdf152..b06f9fd7e4 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1433,7 +1433,7 @@ CREDIT_NOTIFICATION_CACHE_TIMEOUT = 5 * 60 * 60 ################################# Middleware ################################### -MIDDLEWARE_CLASSES = [ +MIDDLEWARE = [ 'openedx.core.lib.x_forwarded_for.middleware.XForwardedForMiddleware', 'crum.CurrentRequestUserMiddleware', diff --git a/lms/envs/devstack.py b/lms/envs/devstack.py index a9aca7b837..300de1229d 100644 --- a/lms/envs/devstack.py +++ b/lms/envs/devstack.py @@ -67,7 +67,7 @@ DJFS = { ################################ DEBUG TOOLBAR ################################ INSTALLED_APPS += ['debug_toolbar'] -MIDDLEWARE_CLASSES += [ +MIDDLEWARE += [ 'lms.djangoapps.discussion.django_comment_client.utils.QueryCountDebugMiddleware', 'debug_toolbar.middleware.DebugToolbarMiddleware', ] diff --git a/lms/envs/load_test.py b/lms/envs/load_test.py index 088584d365..94b042924d 100644 --- a/lms/envs/load_test.py +++ b/lms/envs/load_test.py @@ -19,4 +19,4 @@ EXCLUDE_CSRF = lambda elem: elem not in [ DEFAULT_TEMPLATE_ENGINE['OPTIONS']['context_processors'] = list(filter( EXCLUDE_CSRF, DEFAULT_TEMPLATE_ENGINE['OPTIONS']['context_processors'] )) -MIDDLEWARE_CLASSES = list(filter(EXCLUDE_CSRF, MIDDLEWARE_CLASSES)) +MIDDLEWARE = list(filter(EXCLUDE_CSRF, MIDDLEWARE)) diff --git a/lms/envs/production.py b/lms/envs/production.py index 9eeecec3b1..9f43c48b44 100644 --- a/lms/envs/production.py +++ b/lms/envs/production.py @@ -1098,7 +1098,7 @@ PARENTAL_CONSENT_AGE_LIMIT = ENV_TOKENS.get( ########################## Extra middleware classes ####################### # Allow extra middleware classes to be added to the app through configuration. -MIDDLEWARE_CLASSES.extend(ENV_TOKENS.get('EXTRA_MIDDLEWARE_CLASSES', [])) +MIDDLEWARE.extend(ENV_TOKENS.get('EXTRA_MIDDLEWARE_CLASSES', [])) ########################## Settings for Completion API ##################### diff --git a/openedx/core/djangoapps/safe_sessions/testing.py b/openedx/core/djangoapps/safe_sessions/testing.py index 1678b35bd0..1c56c9f07f 100644 --- a/openedx/core/djangoapps/safe_sessions/testing.py +++ b/openedx/core/djangoapps/safe_sessions/testing.py @@ -20,7 +20,7 @@ def safe_cookie_test_session_patch(): used, by checking the middleware settings. """ return ( - 'openedx.core.djangoapps.safe_sessions.middleware.SafeSessionMiddleware' in settings.MIDDLEWARE_CLASSES + 'openedx.core.djangoapps.safe_sessions.middleware.SafeSessionMiddleware' in settings.MIDDLEWARE ) ## session_id --> safe_cookie_data ## diff --git a/requirements/constraints.txt b/requirements/constraints.txt index 7ae271c4b9..f4ec2f7b54 100644 --- a/requirements/constraints.txt +++ b/requirements/constraints.txt @@ -17,9 +17,6 @@ django-debug-toolbar<2.0 # Version 1.2.0 dropped support for Django 1.11 django-oauth-toolkit<1.2.0 -# Version 1.0.0 dropped support for Django 1.11 simultaneously with adding support for 2.x -django-method-override<1.0.0 - # Version 4.0.0 dropped support for Django < 2.0.1 django-model-utils<4.0.0 diff --git a/requirements/edx/base.in b/requirements/edx/base.in index 0ab2fcf44a..45fec62813 100644 --- a/requirements/edx/base.in +++ b/requirements/edx/base.in @@ -45,7 +45,6 @@ django-crum # Middleware that stores the current request django-fernet-fields # via edx-enterprise (should be added to its setup.py) django-filter # Allows users to filter Django querysets dynamically django-ipware # Get the client's real IP address -django-method-override django-model-utils django-mptt django-mysql diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index 3be614c397..bc5f4b9ab3 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -65,7 +65,7 @@ django-fernet-fields==0.6 django-filter==2.2.0 django-ipware==2.1.0 django-js-asset==1.2.2 # via django-mptt -django-method-override==0.2.0 +git+https://gitlab.com/Ayub-khan/django-method-override.git@5270af321be2e576d8e8b3c4191711a19975c356#egg=django-method-override==1.0.4 django-model-utils==3.0.0 django-mptt==0.11.0 django-multi-email-field==0.6.1 # via edx-enterprise diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index 386959f385..6750897241 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -76,7 +76,7 @@ django-fernet-fields==0.6 django-filter==2.2.0 django-ipware==2.1.0 django-js-asset==1.2.2 -django-method-override==0.2.0 +git+https://gitlab.com/Ayub-khan/django-method-override.git@5270af321be2e576d8e8b3c4191711a19975c356#egg=django-method-override==1.0.4 django-model-utils==3.0.0 django-mptt==0.11.0 django-multi-email-field==0.6.1 diff --git a/requirements/edx/github.in b/requirements/edx/github.in index bb2df0bf6e..05aa2eaa82 100644 --- a/requirements/edx/github.in +++ b/requirements/edx/github.in @@ -87,6 +87,10 @@ git+https://github.com/jazzband/sorl-thumbnail.git@13bedfb7d2970809eda597e3ef793 # remove this fork git+https://github.com/edx/bridgekeeper.git@2423e8d8788c2132ebeec509e1a7b17e1f5b9364#egg=bridgekeeper==0.0 +# Forked to get Django 1.11 new style middleware support from django-method-override. +# This can be removed once edx-platform is using django>=2.x. +git+https://gitlab.com/Ayub-khan/django-method-override.git@5270af321be2e576d8e8b3c4191711a19975c356#egg=django-method-override==1.0.4 + # Our libraries: -e git+https://github.com/edx/codejail.git@4127fc4bd5775cc72aee8d7f0a70e31405e22439#egg=codejail -e git+https://github.com/edx/acid-block.git@98aecba94ecbfa934e2d00262741c0ea9f557fc9#egg=acid-xblock diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index abb54450df..5bc1a12efd 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -74,7 +74,7 @@ django-fernet-fields==0.6 django-filter==2.2.0 django-ipware==2.1.0 django-js-asset==1.2.2 -django-method-override==0.2.0 +git+https://gitlab.com/Ayub-khan/django-method-override.git@5270af321be2e576d8e8b3c4191711a19975c356#egg=django-method-override==1.0.4 django-model-utils==3.0.0 django-mptt==0.11.0 django-multi-email-field==0.6.1