From 69df9780bf41c3508c57e2cfa1b91a75aa6335d8 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 11 May 2021 13:47:33 +0200 Subject: [PATCH 1/4] Update setting MIDDLEWARE_CLASSES to MIDDLEWARE --- .../project_template/project_name/settings.py | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/orchestra/conf/project_template/project_name/settings.py b/orchestra/conf/project_template/project_name/settings.py index 209d91a4..fae6bbc1 100644 --- a/orchestra/conf/project_template/project_name/settings.py +++ b/orchestra/conf/project_template/project_name/settings.py @@ -25,6 +25,7 @@ SECRET_KEY = '{{ secret_key }}' # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True +ALLOWED_HOSTS = [] # Application definition @@ -84,6 +85,21 @@ INSTALLED_APPS = [ ] +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + + 'orchestra.core.caches.RequestCacheMiddleware', + # also handles transations, ATOMIC_REQUESTS does not wrap middlewares + 'orchestra.contrib.orchestration.middlewares.OperationsMiddleware', +] + + ROOT_URLCONF = '{{ project_name }}.urls' TEMPLATES = [ @@ -168,22 +184,6 @@ LOCALE_PATHS = ( ORCHESTRA_SITE_NAME = '{{ project_name }}' -MIDDLEWARE_CLASSES = ( - 'django.contrib.sessions.middleware.SessionMiddleware', - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', - # 'django.middleware.locale.LocaleMiddleware' - 'django.contrib.messages.middleware.MessageMiddleware', - 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'django.middleware.security.SecurityMiddleware', - 'orchestra.core.caches.RequestCacheMiddleware', - # also handles transations, ATOMIC_REQUESTS does not wrap middlewares - 'orchestra.contrib.orchestration.middlewares.OperationsMiddleware', -) - - AUTH_USER_MODEL = 'accounts.Account' From be5e06129af9a3481392d1c36798c1c9f93fc872 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 11 May 2021 13:48:26 +0200 Subject: [PATCH 2/4] Add password validation settings New on Django 1.9 --- .../project_template/project_name/settings.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/orchestra/conf/project_template/project_name/settings.py b/orchestra/conf/project_template/project_name/settings.py index fae6bbc1..576dd0b8 100644 --- a/orchestra/conf/project_template/project_name/settings.py +++ b/orchestra/conf/project_template/project_name/settings.py @@ -143,6 +143,24 @@ DATABASES = { } +# Password validation +# https://docs.djangoproject.com/en/{{ docs_version }}/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + # Internationalization # https://docs.djangoproject.com/en/{{ docs_version }}/topics/i18n/ From 58be94bde2f5d2f8f4e7445e3a539b64883e87ac Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 11 May 2021 14:00:41 +0200 Subject: [PATCH 3/4] Upgrade orchestra middlewares Refactor to changes introduced on Django 1.10 https://docs.djangoproject.com/en/2.1/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware --- orchestra/contrib/orchestration/middlewares.py | 10 +++++----- orchestra/core/caches.py | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/orchestra/contrib/orchestration/middlewares.py b/orchestra/contrib/orchestration/middlewares.py index 2daefe19..61333c56 100644 --- a/orchestra/contrib/orchestration/middlewares.py +++ b/orchestra/contrib/orchestration/middlewares.py @@ -1,15 +1,15 @@ from threading import local from django.contrib.admin.models import LogEntry -from django.urls import resolve from django.db import transaction -from django.db.models.signals import pre_delete, post_save, m2m_changed +from django.db.models.signals import m2m_changed, post_save, pre_delete from django.dispatch import receiver from django.http.response import HttpResponseServerError - +from django.urls import resolve +from django.utils.deprecation import MiddlewareMixin from orchestra.utils.python import OrderedSet -from . import manager, Operation +from . import Operation, manager from .helpers import message_user from .models import BackendLog, BackendOperation @@ -35,7 +35,7 @@ def m2m_collector(sender, *args, **kwargs): OperationsMiddleware.collect(Operation.SAVE, **kwargs) -class OperationsMiddleware(object): +class OperationsMiddleware(MiddlewareMixin): """ Stores all the operations derived from save and delete signals and executes them at the end of the request/response cycle diff --git a/orchestra/core/caches.py b/orchestra/core/caches.py index 9c5e86fb..ebf5f122 100644 --- a/orchestra/core/caches.py +++ b/orchestra/core/caches.py @@ -2,7 +2,7 @@ from threading import currentThread from django.core.cache.backends.dummy import DummyCache from django.core.cache.backends.locmem import LocMemCache - +from django.utils.deprecation import MiddlewareMixin _request_cache = {} @@ -25,21 +25,21 @@ def get_request_cache(): return DummyCache('dummy', {}) -class RequestCacheMiddleware(object): +class RequestCacheMiddleware(MiddlewareMixin): def process_request(self, request): current_thread = currentThread() cache = _request_cache.get(current_thread, RequestCache()) _request_cache[current_thread] = cache cache.clear() - + def clear_cache(self): current_thread = currentThread() if currentThread() in _request_cache: _request_cache[current_thread].clear() - + def process_exception(self, request, exception): self.clear_cache() - + def process_response(self, request, response): self.clear_cache() return response From 0095da61ea4839656b28d858d3d91cff8c9bffeb Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 11 May 2021 14:02:53 +0200 Subject: [PATCH 4/4] Bump to Markdown==3.3.4 Required by Django Rest Framework --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 7e35c884..69fb6965 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,7 +6,7 @@ django-celery==3.2.1 celery==3.1.23 kombu==3.0.35 billiard==3.3.0.23 -Markdown==2.4 +Markdown==3.3.4 djangorestframework==3.10.3 ecdsa==0.11 Pygments==1.6