From 87776dc1caec95a6eaaf011a7356e676722a11a3 Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Wed, 20 Mar 2013 16:51:58 +0100 Subject: [PATCH] Move to Django 1.5, reorg settings. --- ...ettings.py.default => localsettings.py.dev} | 2 ++ project_name/settings.py | 14 -------------- project_name/settings/__init__.py | 18 ++++++++++++++++++ .../30-apps.py => settings/apps.py} | 0 .../40-auth.py => settings/auth.py} | 3 +++ .../20-basic.py => settings/basic.py} | 4 ++++ .../40-context.py => settings/context.py} | 3 +++ .../50-contrib.py => settings/contrib.py} | 0 .../60-custom.py => settings/custom.py} | 0 .../30-locale.py => settings/locale.py} | 0 .../40-logging.py => settings/logging.py} | 0 .../middleware.py} | 3 +++ .../10-paths.py => settings/paths.py} | 0 .../50-static.py => settings/static.py} | 3 +++ project_name/urls.py | 8 ++++++++ project_name/wsgi.py | 4 ++++ requirements.txt | 2 +- 17 files changed, 49 insertions(+), 15 deletions(-) rename project_name/{localsettings.py.default => localsettings.py.dev} (91%) delete mode 100644 project_name/settings.py create mode 100644 project_name/settings/__init__.py rename project_name/{settings.d/30-apps.py => settings/apps.py} (100%) rename project_name/{settings.d/40-auth.py => settings/auth.py} (84%) rename project_name/{settings.d/20-basic.py => settings/basic.py} (96%) rename project_name/{settings.d/40-context.py => settings/context.py} (94%) rename project_name/{settings.d/50-contrib.py => settings/contrib.py} (100%) rename project_name/{settings.d/60-custom.py => settings/custom.py} (100%) rename project_name/{settings.d/30-locale.py => settings/locale.py} (100%) rename project_name/{settings.d/40-logging.py => settings/logging.py} (100%) rename project_name/{settings.d/40-middleware.py => settings/middleware.py} (97%) rename project_name/{settings.d/10-paths.py => settings/paths.py} (100%) rename project_name/{settings.d/50-static.py => settings/static.py} (97%) diff --git a/project_name/localsettings.py.default b/project_name/localsettings.py.dev similarity index 91% rename from project_name/localsettings.py.default rename to project_name/localsettings.py.dev index 5eb05b6..303bfd7 100644 --- a/project_name/localsettings.py.default +++ b/project_name/localsettings.py.dev @@ -8,3 +8,5 @@ if False: INSTALLED_APPS += ('debug_toolbar',) MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',) INTERNAL_IPS = ('127.0.0.1',) + +SECRET_KEY = 'secret_key' diff --git a/project_name/settings.py b/project_name/settings.py deleted file mode 100644 index e9b77f0..0000000 --- a/project_name/settings.py +++ /dev/null @@ -1,14 +0,0 @@ -import os.path -import glob - -conffiles = glob.glob(os.path.join( - os.path.dirname(__file__), 'settings.d', '*.py')) -conffiles.sort() -for f in conffiles: - execfile(os.path.abspath(f)) - -try: - execfile(os.path.abspath(os.path.join( - os.path.dirname(__file__), 'localsettings.py'))) -except IOError: - pass diff --git a/project_name/settings/__init__.py b/project_name/settings/__init__.py new file mode 100644 index 0000000..8ce1902 --- /dev/null +++ b/project_name/settings/__init__.py @@ -0,0 +1,18 @@ +from .paths import * +from .basic import * +from .apps import * +from .locale import * +from .auth import * +from .context import * +from .middleware import * +from .static import * +from .logging import * +from .contrib import * +from .custom import * + + +# Load localsettings, if they exist +try: + from ..localsettings import * +except ImportError: + pass diff --git a/project_name/settings.d/30-apps.py b/project_name/settings/apps.py similarity index 100% rename from project_name/settings.d/30-apps.py rename to project_name/settings/apps.py diff --git a/project_name/settings.d/40-auth.py b/project_name/settings/auth.py similarity index 84% rename from project_name/settings.d/40-auth.py rename to project_name/settings/auth.py index 675db9d..91b062e 100644 --- a/project_name/settings.d/40-auth.py +++ b/project_name/settings/auth.py @@ -1,3 +1,6 @@ +from . import INSTALLED_APPS + + if 'django_cas' in INSTALLED_APPS: AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', diff --git a/project_name/settings.d/20-basic.py b/project_name/settings/basic.py similarity index 96% rename from project_name/settings.d/20-basic.py rename to project_name/settings/basic.py index 0bb3896..65bfd83 100644 --- a/project_name/settings.d/20-basic.py +++ b/project_name/settings/basic.py @@ -1,3 +1,7 @@ +from os import path +from . import PROJECT_DIR + + DEBUG = False TEMPLATE_DEBUG = DEBUG diff --git a/project_name/settings.d/40-context.py b/project_name/settings/context.py similarity index 94% rename from project_name/settings.d/40-context.py rename to project_name/settings/context.py index e161e0b..ec4ef61 100644 --- a/project_name/settings.d/40-context.py +++ b/project_name/settings/context.py @@ -1,3 +1,6 @@ +from . import INSTALLED_APPS + + TEMPLATE_CONTEXT_PROCESSORS = tuple(x for x in ( "django.contrib.auth.context_processors.auth" if "django.contrib.auth" in INSTALLED_APPS else None, diff --git a/project_name/settings.d/50-contrib.py b/project_name/settings/contrib.py similarity index 100% rename from project_name/settings.d/50-contrib.py rename to project_name/settings/contrib.py diff --git a/project_name/settings.d/60-custom.py b/project_name/settings/custom.py similarity index 100% rename from project_name/settings.d/60-custom.py rename to project_name/settings/custom.py diff --git a/project_name/settings.d/30-locale.py b/project_name/settings/locale.py similarity index 100% rename from project_name/settings.d/30-locale.py rename to project_name/settings/locale.py diff --git a/project_name/settings.d/40-logging.py b/project_name/settings/logging.py similarity index 100% rename from project_name/settings.d/40-logging.py rename to project_name/settings/logging.py diff --git a/project_name/settings.d/40-middleware.py b/project_name/settings/middleware.py similarity index 97% rename from project_name/settings.d/40-middleware.py rename to project_name/settings/middleware.py index b211d42..80ffc44 100644 --- a/project_name/settings.d/40-middleware.py +++ b/project_name/settings/middleware.py @@ -1,3 +1,6 @@ +from . import INSTALLED_APPS + + MIDDLEWARE_CLASSES = tuple(x for x in ( 'django.contrib.sessions.middleware.SessionMiddleware' if "django.contrib.sessions" in INSTALLED_APPS else None, diff --git a/project_name/settings.d/10-paths.py b/project_name/settings/paths.py similarity index 100% rename from project_name/settings.d/10-paths.py rename to project_name/settings/paths.py diff --git a/project_name/settings.d/50-static.py b/project_name/settings/static.py similarity index 97% rename from project_name/settings.d/50-static.py rename to project_name/settings/static.py index 770ad98..cc17ecc 100644 --- a/project_name/settings.d/50-static.py +++ b/project_name/settings/static.py @@ -1,3 +1,6 @@ +from os import path + + MEDIA_ROOT = path.join(PROJECT_DIR, 'media/') MEDIA_URL = '/media/' STATIC_ROOT = path.join(PROJECT_DIR, 'static/') diff --git a/project_name/urls.py b/project_name/urls.py index 0d6160f..c579b39 100644 --- a/project_name/urls.py +++ b/project_name/urls.py @@ -24,3 +24,11 @@ if 'django_cas' in settings.INSTALLED_APPS: (r'^accounts/login/$', 'django_cas.views.login'), (r'^accounts/logout/$', 'django_cas.views.logout'), ) + +# Media in DEBUG mode +if settings.DEBUG: + urlpatterns += patterns('', + url(r'^media/(?P.*)$', 'django.views.static.serve', { + 'document_root': settings.MEDIA_ROOT, + }), + ) diff --git a/project_name/wsgi.py b/project_name/wsgi.py index b083a0e..f768265 100644 --- a/project_name/wsgi.py +++ b/project_name/wsgi.py @@ -15,6 +15,10 @@ framework. """ import os +# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks +# if running multiple sites in the same mod_wsgi process. To fix this, use +# mod_wsgi daemon mode with each site in its own daemon process, or use +# os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") # This application object is used by any WSGI server configured to use this diff --git a/requirements.txt b/requirements.txt index 36289aa..7161bde 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,6 @@ -i http://pypi.nowoczesnapolska.org.pl/simple -Django>=1.4,<1.5 +Django>=1.5,<1.6 South>=0.7.4 django-pipeline>=1.2,<1.3 piwik -- 2.20.1