From 5662b56714618d8d3f91a18f6467a184fb2a3ea7 Mon Sep 17 00:00:00 2001 From: Roberto Rosario Date: Thu, 22 Dec 2016 02:51:28 -0400 Subject: [PATCH] Update project to work with Django 1.10.x --- HISTORY.rst | 2 +- docs/releases/2.2.rst | 2 +- manage.py | 19 ++++- mayan/apps/common/forms.py | 2 +- .../management/commands/createsettings.py | 2 +- mayan/settings/base.py | 84 ++++++++++++------- mayan/settings/production.py | 6 +- mayan/wsgi.py | 7 +- requirements/common.txt | 2 +- 9 files changed, 85 insertions(+), 41 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 208b2d734c..b33984818b 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -11,7 +11,7 @@ the user links - New Dashboard view - Moved licenses to their own module in every app -- Update project to work with Django 1.9.11 +- Update project to work with Django 1.10.4. - Tags are alphabetically ordered by label (GitLab #342). - Stop loading theme fonts from the web (GitLab #343). - Add support for attaching multiple tags (GitLab #307). diff --git a/docs/releases/2.2.rst b/docs/releases/2.2.rst index b3ff76e2f3..6e276d060f 100644 --- a/docs/releases/2.2.rst +++ b/docs/releases/2.2.rst @@ -21,7 +21,7 @@ Other changes the user links - Dashboard - Moved licenses to their own module in every app -- Update project to work with Django 1.9.11 +- Update project to work with Django 1.10.4 - Tags are alphabetically ordered by label - Stop loading theme fonts from the web - Add support for attaching multiple tags to single or multiple documents. diff --git a/manage.py b/manage.py index c8d9c5d18b..ce42540bcc 100755 --- a/manage.py +++ b/manage.py @@ -4,7 +4,20 @@ import sys if __name__ == "__main__": os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mayan.settings") - - from django.core.management import execute_from_command_line - + try: + from django.core.management import execute_from_command_line + except ImportError: + # The above import may fail for some other reason. Ensure that the + # issue is really that Django is missing to avoid masking other + # exceptions on Python 2. + try: + import django + except ImportError: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) + raise execute_from_command_line(sys.argv) + diff --git a/mayan/apps/common/forms.py b/mayan/apps/common/forms.py index 8c1c493726..4b93db6a94 100644 --- a/mayan/apps/common/forms.py +++ b/mayan/apps/common/forms.py @@ -111,7 +111,7 @@ class FilterForm(forms.Form): class LicenseForm(FileDisplayForm): - DIRECTORY = ('mayan',) + DIRECTORY = () FILENAME = 'LICENSE' diff --git a/mayan/apps/common/management/commands/createsettings.py b/mayan/apps/common/management/commands/createsettings.py index 93f61a613d..b01269c86e 100644 --- a/mayan/apps/common/management/commands/createsettings.py +++ b/mayan/apps/common/management/commands/createsettings.py @@ -16,7 +16,7 @@ class Command(management.BaseCommand): return get_random_string(50, chars) def handle(self, *args, **options): - path = os.path.join(settings.BASE_DIR, 'mayan', 'settings', 'local.py') + path = os.path.join(settings.BASE_DIR, 'settings', 'local.py') if os.path.exists(path): self.stdout.write(self.style.NOTICE('Existing settings file at: {0}. Backup, remove this file, and try again.'.format(path))) else: diff --git a/mayan/settings/base.py b/mayan/settings/base.py index e683b14547..2754bb9d00 100644 --- a/mayan/settings/base.py +++ b/mayan/settings/base.py @@ -1,15 +1,17 @@ """ -Django settings for Mayan EDMS project. +Django settings for mayan10 project. + +Generated by 'django-admin startproject' using Django 1.10.4. For more information on this file, see -https://docs.djangoproject.com/en/1.6/topics/settings/ +https://docs.djangoproject.com/en/1.10/topics/settings/ For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.6/ref/settings/ +https://docs.djangoproject.com/en/1.10/ref/settings/ """ + from __future__ import unicode_literals -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) import os import sys @@ -17,14 +19,12 @@ from django.utils.translation import ugettext_lazy as _ import mayan -_file_path = os.path.abspath(os.path.dirname(__file__)).split('/') +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -BASE_DIR = '/'.join(_file_path[0:-2]) - -MEDIA_ROOT = os.path.join(BASE_DIR, 'mayan', 'media') +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) # Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ +# See https://docs.djangoproject.com/en/1.10/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = 'secret_key_missing' @@ -103,6 +103,7 @@ INSTALLED_APPS = ( ) MIDDLEWARE_CLASSES = ( + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', @@ -118,10 +119,32 @@ MIDDLEWARE_CLASSES = ( ROOT_URLCONF = 'mayan.urls' +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.i18n', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + 'loaders': [ + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader' + ] + }, + }, +] + WSGI_APPLICATION = 'mayan.wsgi.application' # Database -# https://docs.djangoproject.com/en/1.6/ref/settings/#databases +# https://docs.djangoproject.com/en/1.10/ref/settings/#databases + +MEDIA_ROOT = os.path.join(BASE_DIR, 'media') DATABASES = { 'default': { @@ -130,8 +153,26 @@ DATABASES = { } } +# Password validation +# https://docs.djangoproject.com/en/1.10/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/1.6/topics/i18n/ +# https://docs.djangoproject.com/en/1.10/topics/i18n/ LANGUAGE_CODE = 'en-us' @@ -143,12 +184,13 @@ USE_L10N = True USE_TZ = True -STATIC_URL = '/static/' +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.10/howto/static-files/ +STATIC_URL = '/static/' # ------------ Custom settings section ---------- -TEMPLATE_DEBUG = True PROJECT_TITLE = mayan.__title__ PROJECT_WEBSITE = 'http://www.mayan-edms.com' PROJECT_COPYRIGHT = mayan.__copyright__ @@ -182,24 +224,10 @@ LANGUAGES = ( SITE_ID = 1 -sys.path.append(os.path.join(BASE_DIR, 'mayan', 'apps')) +sys.path.append(os.path.join(BASE_DIR, 'apps')) STATIC_ROOT = os.path.join(MEDIA_ROOT, 'static') -# List of callables that know how to import templates from various sources. -TEMPLATE_LOADERS = ( - 'django.template.loaders.filesystem.Loader', - 'django.template.loaders.app_directories.Loader' -) - -TEMPLATE_CONTEXT_PROCESSORS = ( - 'django.contrib.auth.context_processors.auth', - 'django.core.context_processors.debug', - 'django.core.context_processors.i18n', - 'django.core.context_processors.request', - 'django.contrib.messages.context_processors.messages', -) - STATICFILES_FINDERS = ( 'django.contrib.staticfiles.finders.FileSystemFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder', diff --git a/mayan/settings/production.py b/mayan/settings/production.py index aae3cd3988..f14639d1b9 100644 --- a/mayan/settings/production.py +++ b/mayan/settings/production.py @@ -8,11 +8,11 @@ DEBUG = False # https://docs.djangoproject.com/en/dev/ref/settings/#allowed-hosts ALLOWED_HOSTS = ['*'] -TEMPLATE_LOADERS = ( - ('django.template.loaders.cached.Loader', ( +TEMPLATES['OPTIONS']['loaders'] = ( + 'django.template.loaders.cached.Loader', ( 'django.template.loaders.filesystem.Loader', 'django.template.loaders.app_directories.Loader', - )), + ) ) CELERY_ALWAYS_EAGER = False diff --git a/mayan/wsgi.py b/mayan/wsgi.py index 57bc2a17b3..d6436e3de7 100644 --- a/mayan/wsgi.py +++ b/mayan/wsgi.py @@ -4,11 +4,14 @@ WSGI config for mayan 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.6/howto/deployment/wsgi/ +https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/ """ import os -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mayan.settings.production") from django.core.wsgi import get_wsgi_application + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mayan.settings.production") + application = get_wsgi_application() + diff --git a/requirements/common.txt b/requirements/common.txt index 2c0e089e77..0ed563f2f8 100644 --- a/requirements/common.txt +++ b/requirements/common.txt @@ -1,2 +1,2 @@ -r base.txt -Django==1.9.11 +Django==1.10.4