From 3ad753235b838c3736ed71398e87aacd04b2f557 2016-10-18 22:36:06 From: Branko Majic Date: 2016-10-18 22:36:06 Subject: [PATCH] MDT-3: Renamed existing project template directory so it clearly identifies it belongs to Django 1.8. Replaced the existing project template for Django 1.8 with new, simplified and improved version. --- diff --git a/docs/development.rst b/docs/development.rst index 19c4c758b20a80c5f2b78733a63fb850f2e18843..e0955a8e48b8fa01721bc366a03680aad167f789 100644 --- a/docs/development.rst +++ b/docs/development.rst @@ -195,18 +195,19 @@ This is just a rough outline of what needs to be done. STATIC_URL = '/static/' MEDIA_URL = '/media/' - # Absolute filesystem path to directory that will hold user-uploaded - # files. + # Directory for storing and serving user-uploaded files. MEDIA_ROOT = os.path.normpath(os.path.join(ASSETS_ROOT, "media")) - # Absolute filesystem path to directory that will hold static files. + # Directory for storing and serving static files. STATIC_ROOT = os.path.normpath(os.path.join(ASSETS_ROOT, "static")) - # Additional locations for static files. Useful for project-wide overrides of - # default static files. + # Additional directories from which to read the static files. This can be + # used for overriding application static files on project basis. STATICFILES_DIRS = ( os.path.normpath(os.path.join(BASE_DIR, "static")), ) + - Update remaining Python files. You may want to template things like + documentation version, Django version etc. 9. At this point you need to be a bit more creative. Depending on Django version, you may need to isolate different settings to be part of the base diff --git a/project/manage.py b/project-django-1.8/manage.py similarity index 100% rename from project/manage.py rename to project-django-1.8/manage.py diff --git a/project/project_name/__init__.py b/project-django-1.8/project_name/__init__.py similarity index 100% rename from project/project_name/__init__.py rename to project-django-1.8/project_name/__init__.py diff --git a/project/project_name/settings/__init__.py b/project-django-1.8/project_name/settings/__init__.py similarity index 100% rename from project/project_name/settings/__init__.py rename to project-django-1.8/project_name/settings/__init__.py diff --git a/project/project_name/settings/base.py b/project-django-1.8/project_name/settings/base.py similarity index 50% rename from project/project_name/settings/base.py rename to project-django-1.8/project_name/settings/base.py index 5025e2fbbcc2906e469fc00139706f637836b712..b5cf9be48f77ed1b1dde7e91196cd2ea0c47b95c 100644 --- a/project/project_name/settings/base.py +++ b/project-django-1.8/project_name/settings/base.py @@ -1,17 +1,34 @@ -# Common Django settings for all environments for project {{ project_name }}. - # -# This file contains common settings shared amongst all environments of a -# project. Do not put any environment-specific settings here. +# Base settings for Django project {{ project_name }}. These settings are shared +# across all environments. +# +# Project created from template using Django {{ django_version }}. +# +# In order to specify environment-specific settings, use files: +# +# development.py +# testing.py +# staging.py +# production.py # +# For more information on this file see +# https://docs.djangoproject.com/en/1.8/topics/settings/ +# +# For the full list of settings and their values, see +# https://docs.djangoproject.com/en/1.8/ref/settings/ + +# Base paths for accessing project root directory and directory where assets are +# stored. Other paths can be built relative to these directories with: +# os.path.join(BASE_DIR, ...) +# os.path.join(ASSETS_DIR, ...) import os -# Determine the root and assets project directories. -PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -ASSETS_ROOT = os.path.normpath(os.path.join(PROJECT_ROOT, "assets")) +# Base and assets project directories. +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +ASSETS_ROOT = os.path.normpath(os.path.join(BASE_DIR, "assets")) -# Applications installed in the project. +# List of installed applications. INSTALLED_APPS = ( 'django.contrib.admin', 'django.contrib.auth', @@ -21,7 +38,7 @@ INSTALLED_APPS = ( 'django.contrib.staticfiles', ) -# Middleware classes enabled in the project. +# List of middleware classes to apply to incoming requests. MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', @@ -33,10 +50,10 @@ MIDDLEWARE_CLASSES = ( 'django.middleware.security.SecurityMiddleware', ) -# URL configuration for the project. +# URL configuration to use for serving project root. ROOT_URLCONF = '{{ project_name }}.urls' -# Templates configuration for the project. +# Template lookup and rendering configuration. TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', @@ -53,11 +70,15 @@ TEMPLATES = [ }, ] -# Python dotted path to the WSGI application used by Django's runserver command. +# WSGI application module for running the project. WSGI_APPLICATION = '{{ project_name }}.wsgi.application' -# Language, internationalisation, and time configuration +# Language, internationalisation, and time configuration. +# +# For details see +# https://docs.djangoproject.com/en/1.8/topics/i18n/ LANGUAGE_CODE = 'en-us' +TIME_ZONE = 'Europe/Stockholm' USE_I18N = True USE_L10N = True USE_TZ = True @@ -66,16 +87,14 @@ USE_TZ = True STATIC_URL = '/static/' MEDIA_URL = '/media/' -# Absolute filesystem path to the directory that will hold user-uploaded -# files. Calculated based on assets root. +# Directory for storing and serving user-uploaded files. MEDIA_ROOT = os.path.normpath(os.path.join(ASSETS_ROOT, "media")) -# Absolute path to the directory static files should be collected to. Calculated -# based on project assets root. +# Directory for storing and serving static files. STATIC_ROOT = os.path.normpath(os.path.join(ASSETS_ROOT, "static")) -# Additional locations for static files. Useful for project-wide overrides of -# default static files. +# Additional directories from which to read the static files. This can be +# used for overriding application static files on project basis. STATICFILES_DIRS = ( - os.path.normpath(os.path.join(PROJECT_ROOT, "static")), + os.path.normpath(os.path.join(BASE_DIR, "static")), ) diff --git a/project-django-1.8/project_name/settings/development.py b/project-django-1.8/project_name/settings/development.py new file mode 100644 index 0000000000000000000000000000000000000000..01675d7ac682c283b61a5827cb6be21218a46538 --- /dev/null +++ b/project-django-1.8/project_name/settings/development.py @@ -0,0 +1,30 @@ +# Development environment settings for project {{ project_name }}. + +# Import the base settings. +from .base import * + +# Credentials in development environment are static. +SECRET_KEY="{{ secret_key }}" + +# Enable debugging in development environment. +DEBUG = True +for template_config in TEMPLATES: + template_config['OPTIONS']['debug']=True + +# Site administrators and managers. +ADMINS = ( + # ('Your Name', 'your_email@example.com'), +) +MANAGERS = ADMINS + +# Use SQLite3 for simplicity in development environment. +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': 'development.sqlite3', + 'USER': '', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '', + } +} diff --git a/project-django-1.8/project_name/settings/production.py b/project-django-1.8/project_name/settings/production.py new file mode 100644 index 0000000000000000000000000000000000000000..dfbb9e7fba36c095540a6c52a84cd3951da863e8 --- /dev/null +++ b/project-django-1.8/project_name/settings/production.py @@ -0,0 +1,41 @@ +# Production environment settings for project {{ project_name }}. + +# Import the base settings. +from .base import * + +# Import credentials. +try: + from .credentials import DATABASE_PASSWORD +except ImportError: + raise ImproperlyConfigured("Please configure DATABASE_PASSWORD in credentials.py.") + +try: + from .credentials import SECRET_KEY +except ImportError: + raise ImproperlyConfigured("Please configure SECRET_KEY in credentials.py.") + +# Disable debugging. +DEBUG = False +for template_config in TEMPLATES: + template_config['OPTIONS']['debug']=False + +# Site administrators and managers. +ADMINS = ( + # ('Your Name', 'your_email@example.com'), +) +MANAGERS = ADMINS + +# Database configuration. +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': '{{ project_name }}', + 'USER': '{{ project_name }}', + 'PASSWORD': DATABASE_PASSWORD, + 'HOST': '127.0.0.1', + 'PORT': '', + } +} + +# Hostnames/FQDNs considered valid for accessing the installation. +ALLOWED_HOSTS = [] diff --git a/project-django-1.8/project_name/settings/staging.py b/project-django-1.8/project_name/settings/staging.py new file mode 100644 index 0000000000000000000000000000000000000000..fde3c84449622ebaa778044b956b5ef91b5453a3 --- /dev/null +++ b/project-django-1.8/project_name/settings/staging.py @@ -0,0 +1,41 @@ +# Staging environment settings for project {{ project_name }}. + +# Import the base settings. +from .base import * + +# Import credentials. +try: + from .credentials import DATABASE_PASSWORD +except ImportError: + raise ImproperlyConfigured("Please configure DATABASE_PASSWORD in credentials.py.") + +try: + from .credentials import SECRET_KEY +except ImportError: + raise ImproperlyConfigured("Please configure SECRET_KEY in credentials.py.") + +# Disable debugging. +DEBUG = False +for template_config in TEMPLATES: + template_config['OPTIONS']['debug']=False + +# Site administrators and managers. +ADMINS = ( + # ('Your Name', 'your_email@example.com'), +) +MANAGERS = ADMINS + +# Database configuration. +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': '{{ project_name }}', + 'USER': '{{ project_name }}', + 'PASSWORD': DATABASE_PASSWORD, + 'HOST': '127.0.0.1', + 'PORT': '', + } +} + +# Hostnames/FQDNs considered valid for accessing the installation. +ALLOWED_HOSTS = [] diff --git a/project-django-1.8/project_name/settings/testing.py b/project-django-1.8/project_name/settings/testing.py new file mode 100644 index 0000000000000000000000000000000000000000..98c4939e1e1405f77801c8968293442282e7e6a6 --- /dev/null +++ b/project-django-1.8/project_name/settings/testing.py @@ -0,0 +1,41 @@ +# Testing environment settings for project {{ project_name }}. + +# Import the base settings. +from .base import * + +# Import credentials. +try: + from .credentials import DATABASE_PASSWORD +except ImportError: + raise ImproperlyConfigured("Please configure DATABASE_PASSWORD in credentials.py.") + +try: + from .credentials import SECRET_KEY +except ImportError: + raise ImproperlyConfigured("Please configure SECRET_KEY in credentials.py.") + +# Disable debugging. +DEBUG = False +for template_config in TEMPLATES: + template_config['OPTIONS']['debug']=False + +# Site administrators and managers. +ADMINS = ( + # ('Your Name', 'your_email@example.com'), +) +MANAGERS = ADMINS + +# Database configuration. +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': '{{ project_name }}', + 'USER': '{{ project_name }}', + 'PASSWORD': DATABASE_PASSWORD, + 'HOST': '127.0.0.1', + 'PORT': '', + } +} + +# Hostnames/FQDNs considered valid for accessing the installation. +ALLOWED_HOSTS = [] diff --git a/project/project_name/urls.py b/project-django-1.8/project_name/urls.py similarity index 83% rename from project/project_name/urls.py rename to project-django-1.8/project_name/urls.py index 665085b17b91fdddf17c21aee55655cf926eca96..cbc982dffc9ba9257dbffe0f0e7b20b0b330f67b 100644 --- a/project/project_name/urls.py +++ b/project-django-1.8/project_name/urls.py @@ -10,8 +10,7 @@ Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: url(r'^$', Home.as_view(), name='home') Including another URLconf - 1. Add an import: from blog import urls as blog_urls - 2. Add a URL to urlpatterns: url(r'^blog/', include(blog_urls)) + 1. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls')) """ from django.conf.urls import include, url from django.contrib import admin diff --git a/project/project_name/wsgi.py b/project-django-1.8/project_name/wsgi.py similarity index 100% rename from project/project_name/wsgi.py rename to project-django-1.8/project_name/wsgi.py diff --git a/project/project_name/settings/development.py b/project/project_name/settings/development.py deleted file mode 100644 index ff665a8a1dc2d39c50319e9ec9fb8ba68e698f81..0000000000000000000000000000000000000000 --- a/project/project_name/settings/development.py +++ /dev/null @@ -1,52 +0,0 @@ -# Development environment settings for project {{ project_name }}. - -# -# This configuration file is used to define settings for the development -# environment. -# - -# Import the exception for signaling invalid configuration. No other -# Django-specific definitions should be imported here. -from django.core.exceptions import ImproperlyConfigured - -# Import the base settings. -from .base import * - -# Import the credentials. -try: - from .credentials import DATABASE_PASSWORDS -except ImportError: - raise ImproperlyConfigured("Please configure the DATABASE_PASSWORDS in credentials.py.") - -try: - from .credentials import SECRET_KEY -except ImportError: - raise ImproperlyConfigured("Please configure the SECRET_KEY in credentials.py.") - -# Debugging is useful for development. -DEBUG = True -for template_config in TEMPLATES: - template_config['OPTIONS']['debug']=True - -# Site administrators and managers. -ADMINS = ( - # ('Your Name', 'your_email@example.com'), -) -MANAGERS = ADMINS - -# Database configuration. sqlite3 is used for development for convenience. See -# testing/production environment settings and official Django documentation if a -# proper database should be used. -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': 'development.sqlite3', - } -} - -# Hosts that are valid for accessing this site. For development, empty list is -# sufficient. -ALLOWED_HOSTS = [] - -# Local time zone for development environment. -TIME_ZONE = 'Europe/Stockholm' diff --git a/project/project_name/settings/production.py b/project/project_name/settings/production.py deleted file mode 100644 index e2f8211ce31e6037e672a5931de88a843436b4c4..0000000000000000000000000000000000000000 --- a/project/project_name/settings/production.py +++ /dev/null @@ -1,66 +0,0 @@ -# Production environment settings for project {{ project_name }}. - -# -# This configuration file is used to define settins for the production -# environment. -# - -# Import the exception for signaling invalid configuration. No other -# Django-specific definitions should be imported here. -from django.core.exceptions import ImproperlyConfigured - -# Import the base settings. -from .base import * - -# Import the credentials. -try: - from .credentials import DATABASE_PASSWORDS -except ImportError: - raise ImproperlyConfigured("Please configure the DATABASE_PASSWORDS in credentials.py.") - -try: - from .credentials import SECRET_KEY -except ImportError: - raise ImproperlyConfigured("Please configure the SECRET_KEY in credentials.py.") - -# Debugging should normally be disabled in production environment, but may be -# necessary in case of serious issues that cannot be reproduced in test -# environment. -DEBUG = False -for template_config in TEMPLATES: - template_config['OPTIONS']['debug']=False - -# Site administrators and managers. -ADMINS = ( - # ('Your Name', 'your_email@example.com'), -) -MANAGERS = ADMINS - -# Database configuration. Avoid using sqlite3 for production environments. -DATABASES = { - 'default': { - # Database engine to use. Set it to 'postgresql_psycopg2', 'mysql', - # 'sqlite3' or 'oracle' (keep the django.db.backends prefix). - 'ENGINE': 'django.db.backends.', - # Name of database, or path to database file if using sqlite3. - 'NAME': '', - # Username for logging-in into database server. Not required for - # sqlite3. - 'USER': '', - # Password for logging-in into database server. Should be read from - # credentials.py. - 'PASSWORD': DATABASE_PASSWORDS['default'], - # IP or resolvable name of the database server. - 'HOST': '127.0.0.1', - # Port on which the database server accepts incoming connections. If not - # specified, engine-specific port is set automatically. - 'PORT': '', - } -} - -# Hosts that are valid for accessing this site. Must be set for production -# environment. -ALLOWED_HOSTS = [] - -# Local time zone for production environment. -TIME_ZONE = 'Europe/Stockholm' diff --git a/project/project_name/settings/sample_credentials.py b/project/project_name/settings/sample_credentials.py deleted file mode 100644 index 1556bf1f5475a99d81b15653288f377e2453c877..0000000000000000000000000000000000000000 --- a/project/project_name/settings/sample_credentials.py +++ /dev/null @@ -1,15 +0,0 @@ -# Sample credentials.py file. - -# -# This file contains a sample of how the site-specific credentials.py file -# should look like. -# - -# Secret key should be unique and kept secret. It should also be sufficiently -# complex to prevent brute-forcing. -SECRET_KEY = '' - -# Passwords for one or more databases used by the site. -DATABASE_PASSWORDS = { - 'default': '', - } diff --git a/project/project_name/settings/testing.py b/project/project_name/settings/testing.py deleted file mode 100644 index 9894a141ba85181aecd291a8b7785857992d9a90..0000000000000000000000000000000000000000 --- a/project/project_name/settings/testing.py +++ /dev/null @@ -1,66 +0,0 @@ -# Testing environment settings for project {{ project_name }}. - -# -# This configuration file is used to define settings for the testing -# environment. -# - -# Import the exception for signaling invalid configuration. No other -# Django-specific definitions should be imported here. -from django.core.exceptions import ImproperlyConfigured - -# Import the base settings. -from .base import * - -# Import the credentials. -try: - from .credentials import DATABASE_PASSWORDS -except ImportError: - raise ImproperlyConfigured("Please configure the DATABASE_PASSWORDS in credentials.py.") - -try: - from .credentials import SECRET_KEY -except ImportError: - raise ImproperlyConfigured("Please configure the SECRET_KEY in credentials.py.") - -# Debugging should normally be disabled in test environment, but may be -# necessary in some cases. -DEBUG = False -for template_config in TEMPLATES: - template_config['OPTIONS']['debug']=False - -# Site administrators and managers. -ADMINS = ( - # ('Your Name', 'your_email@example.com'), -) -MANAGERS = ADMINS - -# Database configuration. Testing environment should use database configuration -# as similar to production as possible. -DATABASES = { - 'default': { - # Database engine to use. Set it to 'postgresql_psycopg2', 'mysql', - # 'sqlite3' or 'oracle' (keep the django.db.backends prefix). - 'ENGINE': 'django.db.backends.', - # Name of database, or path to database file if using sqlite3. - 'NAME': '', - # Username for logging-in into database server. Not required for - # sqlite3. - 'USER': '', - # Password for logging-in into database server. Should be read from - # credentials.py. - 'PASSWORD': DATABASE_PASSWORDS['default'], - # IP or resolvable name of the database server. - 'HOST': '127.0.0.1', - # Port on which the database server accepts incoming connections. If not - # specified, engine-specific port is set automatically. - 'PORT': '', - } -} - -# Hosts that are valid for accessing this site. Must be set for testing -# environment. -ALLOWED_HOSTS = [] - -# Local time zone for testing environment. -TIME_ZONE = 'Europe/Stockholm'