From: Radek Czajka Date: Fri, 26 Jun 2015 19:33:15 +0000 (+0200) Subject: Django 1.8 X-Git-Url: https://git.mdrn.pl/fnp-django-template.git/commitdiff_plain/92978d8c53e45701d995ebe54ac082f2dfe2b659?ds=sidebyside Django 1.8 --- diff --git a/bootstrap.sh b/bootstrap.sh index ffee400..36d799d 100644 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -8,7 +8,7 @@ # Make it a function, so that it works with `source` start_project() { -local DJANGO_REQ='Django>=1.7,<1.8' +local DJANGO_REQ='Django>=1.8,<1.9' local DJANGO_ROOT='src' local PYPI='https://py.mdrn.pl:8443/simple' local DEFAULT_PYTHON="`which python3.4`" @@ -109,13 +109,14 @@ cd "$PROJECT" chmod +x "$DJANGO_ROOT"/manage.py mv _gitignore .gitignore +cp etc/local_settings.py.sample etc/local_settings.py +cp etc/local_settings_test.py.sample etc/local_settings_test.py +ln -s ../../../etc/local_settings.py ../../../etc/local_settings_test.py $DJANGO_ROOT/$PROJECT/settings/ echo -e "${strong}Installing requirements...${normal}" -pip install -i "$PYPI" -r requirements.txt -echo -e "${strong}Installing developer requirements...${normal}" -pip install -i "$PYPI" -r requirements-dev.txt -echo -e "${strong}Running syncdb...${normal}" -"$DJANGO_ROOT"/manage.py syncdb --noinput +pip install -i "$PYPI" -r requirements/dev.txt +echo -e "${strong}Running migrate...${normal}" +"$DJANGO_ROOT"/manage.py migrate #--noinput echo -e "${strong}Starting new git repository...${normal}" git init diff --git a/src/_gitignore b/src/_gitignore index 3fd46ac..2b0134e 100644 --- a/src/_gitignore +++ b/src/_gitignore @@ -1,5 +1,5 @@ /var -localsettings.py +etc/local_settings*.py *~ *.orig *.log diff --git a/src/etc/local_settings.py.sample b/src/etc/local_settings.py.sample new file mode 100644 index 0000000..354ae96 --- /dev/null +++ b/src/etc/local_settings.py.sample @@ -0,0 +1,5 @@ +from .dev import * + +ADMINS = [ + # ('Your Name', 'your_email@domain.com'), +] diff --git a/src/etc/local_settings_test.py.sample b/src/etc/local_settings_test.py.sample new file mode 100644 index 0000000..e69de29 diff --git a/src/requirements-dev.txt b/src/requirements-dev.txt deleted file mode 100644 index fe1e0c6..0000000 --- a/src/requirements-dev.txt +++ /dev/null @@ -1,3 +0,0 @@ --i https://py.mdrn.pl:8443/simple - -fnpdeploy diff --git a/src/requirements.txt b/src/requirements.txt deleted file mode 100644 index aea9e3c..0000000 --- a/src/requirements.txt +++ /dev/null @@ -1,13 +0,0 @@ --i https://py.mdrn.pl:8443/simple - -Django>=1.7,<1.8 -django-pipeline>=1.3,<1.4 -django-piwik -#pyScss -#git+git://github.com/Kronuz/pyScss.git@d8f4da23a3c87696a75b3830ed4ab49b75550a93#egg=pyScss -#TODO: pyScss support, for now just install sass - -django_cas_ng>=3.4,<3.5 -fnpdjango>=0.2,<0.3 - -ipython diff --git a/src/requirements/base.txt b/src/requirements/base.txt new file mode 100644 index 0000000..75103cd --- /dev/null +++ b/src/requirements/base.txt @@ -0,0 +1,13 @@ +-i https://py.mdrn.pl:8443/simple + +Django>=1.8,<1.9 +django-pipeline>=1.3,<1.4 +django-piwik +#pyScss +#git+git://github.com/Kronuz/pyScss.git@d8f4da23a3c87696a75b3830ed4ab49b75550a93#egg=pyScss +#TODO: pyScss support, for now just install sass + +django_cas_ng>=3.4,<3.5 +fnpdjango>=0.2,<0.3 + +ipython diff --git a/src/requirements/dev.txt b/src/requirements/dev.txt new file mode 100644 index 0000000..4ec2c99 --- /dev/null +++ b/src/requirements/dev.txt @@ -0,0 +1,3 @@ +-r base.txt + +fnpdeploy diff --git a/src/src/project_name/localsettings.py b/src/src/project_name/localsettings.py deleted file mode 100644 index 303bfd7..0000000 --- a/src/src/project_name/localsettings.py +++ /dev/null @@ -1,12 +0,0 @@ -DEBUG = True -ADMINS = MANAGERS = [ - ('Admin', 'admin@example.com'), -] -EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' - -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/src/src/project_name/settings/__init__.py b/src/src/project_name/settings/__init__.py index 8ce1902..a7020f2 100644 --- a/src/src/project_name/settings/__init__.py +++ b/src/src/project_name/settings/__init__.py @@ -1,18 +1,34 @@ -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 * +# -*- coding: utf-8 -*- +# Settings loader for {{ project_name }} project. +from __future__ import unicode_literals +import sys -# Load localsettings, if they exist -try: - from ..localsettings import * -except ImportError: - pass + +if len(sys.argv) > 1 and sys.argv[1] == 'test': + try: + from .local_settings_test import * + except ImportError: + from os import path + local_settings_path = path.dirname(__file__) + '/local_settings_test.py' + if not path.exists(local_settings_path): + # No local test settings. + from .test import * + else: + # Error in local test settings - propagate. + raise +else: + try: + from .local_settings import * + except ImportError: + from os import path + local_settings_path = path.dirname(__file__) + '/local_settings.py' + if not path.exists(local_settings_path): + # No local settings file. + # Assuming dev mode, because the file would've been created during deployment. + from warnings import warn + warn("File '%s' does not exist. Loading dev settings as a fallback." % local_settings_path) + from .dev import * + else: + # Error in local settings - propagate. + raise diff --git a/src/src/project_name/settings/apps.py b/src/src/project_name/settings/apps.py deleted file mode 100644 index bf246ff..0000000 --- a/src/src/project_name/settings/apps.py +++ /dev/null @@ -1,16 +0,0 @@ -INSTALLED_APPS = ( - '{{ project_name }}', - 'fnpdjango', - 'pipeline', - # Disable, if not using Piwik. - 'piwik', - - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.sites', - 'django.contrib.messages', - 'django.contrib.staticfiles', - 'django.contrib.admin', - 'django.contrib.admindocs', -) diff --git a/src/src/project_name/settings/auth.py b/src/src/project_name/settings/auth.py deleted file mode 100644 index e914ebb..0000000 --- a/src/src/project_name/settings/auth.py +++ /dev/null @@ -1,6 +0,0 @@ -# Remove if not using CAS. -AUTHENTICATION_BACKENDS = ( - 'django.contrib.auth.backends.ModelBackend', - 'django_cas_ng.backends.CASBackend', -) - diff --git a/src/src/project_name/settings/base.py b/src/src/project_name/settings/base.py new file mode 100644 index 0000000..2aa4a33 --- /dev/null +++ b/src/src/project_name/settings/base.py @@ -0,0 +1,136 @@ +# -*- coding: utf-8 -*- +# Base settings for {{ project_name }} project. +from __future__ import unicode_literals + +from os import path + +PROJECT_DIR = path.dirname(path.dirname(path.dirname(path.abspath(path.dirname(__file__))))) + + +# ============= +# DJANGO CORE +# ============= + +INSTALLED_APPS = ( + '{{ project_name }}', + 'fnpdjango', + 'pipeline', + # Disable, if not using Piwik. + 'piwik', + + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.messages', + 'django.contrib.sessions', + 'django.contrib.staticfiles', +) + +LANGUAGE_CODE = 'pl' + +LANGUAGES = ( + ('pl', u'polski'), +# ('en', u'English'), +) + +MEDIA_ROOT = path.join(PROJECT_DIR, 'var/media/') +MEDIA_URL = '/media/' + +MIDDLEWARE_CLASSES = [ + 'django.contrib.sessions.middleware.SessionMiddleware', + #'django.middleware.locale.LocaleMiddleware', + 'fnpdjango.middleware.URLLocaleMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django_cas_ng.middleware.CASMiddleware', # Remove if not using CAS. + 'django.contrib.messages.middleware.MessageMiddleware', + 'fnpdjango.middleware.SetRemoteAddrFromXRealIP' +] + +ROOT_URLCONF = '{{ project_name }}.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + 'django.template.context_processors.i18n', + ], + }, + }, +] + + +TIME_ZONE = 'Europe/Warsaw' +USE_I18N = True +USE_L10N = True +USE_TZ = True +WSGI_APPLICATION = '{{ project_name }}.wsgi.application' + + +# ============= +# DJANGO AUTH +# ============= + +# Remove if not using CAS. +AUTHENTICATION_BACKENDS = ( + 'django.contrib.auth.backends.ModelBackend', + 'django_cas_ng.backends.CASBackend', +) + +# =============== +# DJANGO STATIC +# =============== + +STATIC_ROOT = path.join(PROJECT_DIR, 'var/static/') +STATIC_URL = '/static/' +STATICFILES_STORAGE = 'fnpdjango.utils.pipeline_storage.GzipPipelineCachedStorage' + +STATICFILES_FINDERS = [ + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'pipeline.finders.PipelineFinder', +] + + +# ======== +# CAS_NG +# ======== + +CAS_SERVER_URL = 'https://logowanie.nowoczesnapolska.org.pl/cas/' +CAS_VERSION = '3' + + +# ========== +# PIPELINE +# ========== + +PIPELINE_CSS = { + 'base': { + 'source_filenames': ( + 'css/base.scss', + ), + 'output_filename': 'compressed/base.css', + }, +} + +PIPELINE_JS = { + 'base': { + 'source_filenames': ( + 'jquery.min.js', + ), + 'output_filename': 'compressed/base.js', + }, +} + +PIPELINE_CSS_COMPRESSOR = None +PIPELINE_JS_COMPRESSOR = None + +PIPELINE_COMPILERS = ( + 'pipeline.compilers.sass.SASSCompiler', +) diff --git a/src/src/project_name/settings/basic.py b/src/src/project_name/settings/basic.py deleted file mode 100644 index f5dcfb8..0000000 --- a/src/src/project_name/settings/basic.py +++ /dev/null @@ -1,41 +0,0 @@ -from os import path -from . import PROJECT_DIR - - -DEBUG = False -TEMPLATE_DEBUG = DEBUG - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. - 'NAME': path.join(PROJECT_DIR, 'var', 'dev.db'), # Or path to database file if using sqlite3. - 'USER': '', # Not used with sqlite3. - 'PASSWORD': '', # Not used with sqlite3. - 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. - 'PORT': '', # Set to empty string for default. Not used with sqlite3. - } -} - -SITE_ID = 1 - -SILENCED_SYSTEM_CHECKS = [ - '1_6.W001', - ] - -# 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', -# 'django.template.loaders.eggs.Loader', -) - -ROOT_URLCONF = '{{ project_name }}.urls' - -# Python dotted path to the WSGI application used by Django's runserver. -WSGI_APPLICATION = '{{ project_name }}.wsgi.application' - -TEMPLATE_DIRS = ( - # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". - # Always use forward slashes, even on Windows. - # Don't forget to use absolute paths, not relative paths. -) diff --git a/src/src/project_name/settings/context.py b/src/src/project_name/settings/context.py deleted file mode 100644 index 46eea9d..0000000 --- a/src/src/project_name/settings/context.py +++ /dev/null @@ -1,13 +0,0 @@ -from . import INSTALLED_APPS - - -TEMPLATE_CONTEXT_PROCESSORS = tuple(x for x in ( - "django.contrib.auth.context_processors.auth", - "django.core.context_processors.debug", - "django.core.context_processors.i18n", - "django.core.context_processors.media", - "django.core.context_processors.static", - "django.core.context_processors.tz", - "django.contrib.messages.context_processors.messages", - "django.core.context_processors.request" -) if x is not None) diff --git a/src/src/project_name/settings/contrib.py b/src/src/project_name/settings/contrib.py deleted file mode 100644 index fe850ed..0000000 --- a/src/src/project_name/settings/contrib.py +++ /dev/null @@ -1,3 +0,0 @@ -# CAS-specific -CAS_SERVER_URL = 'https://logowanie.nowoczesnapolska.org.pl/cas/' -CAS_VERSION = '3' diff --git a/src/src/project_name/settings/custom.py b/src/src/project_name/settings/custom.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/src/project_name/settings/dev.py b/src/src/project_name/settings/dev.py new file mode 100644 index 0000000..be2fb78 --- /dev/null +++ b/src/src/project_name/settings/dev.py @@ -0,0 +1,29 @@ +from .base import * + +_DEBUG_TOOLBAR = False + +ADMINS = MANAGERS = [ + ('Admin', 'admin@example.com'), +] + +DEBUG = True + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': path.join(PROJECT_DIR, 'var', 'db.sqlite3'), + } +} + +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +INTERNAL_IPS = ['127.0.0.1'] +SECRET_KEY = 'secret_key' + +for _t in TEMPLATES: + _t['OPTIONS']['debug'] = DEBUG + _t['OPTIONS']['context_processors'].append('django.template.context_processors.debug') + +if _DEBUG_TOOLBAR: + INSTALLED_APPS += ('debug_toolbar',) + MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',) + diff --git a/src/src/project_name/settings/locale.py b/src/src/project_name/settings/locale.py deleted file mode 100644 index d77583d..0000000 --- a/src/src/project_name/settings/locale.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- - -LANGUAGES = ( - ('pl', u'polski'), -# ('en', u'English'), -) - -# Local time zone for this installation. Choices can be found here: -# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name -# although not all choices may be available on all operating systems. -# On Unix systems, a value of None will cause Django to use the same -# timezone as the operating system. -# If running in a Windows environment this must be set to the same as your -# system time zone. -TIME_ZONE = None - -# Language code for this installation. All choices can be found here: -# http://www.i18nguy.com/unicode/language-identifiers.html -LANGUAGE_CODE = 'pl' - -# If you set this to False, Django will make some optimizations so as not -# to load the internationalization machinery. -USE_I18N = True - -# If you set this to False, Django will not format dates, numbers and -# calendars according to the current locale. -USE_L10N = True - -# If you set this to False, Django will not use timezone-aware datetimes. -USE_TZ = True diff --git a/src/src/project_name/settings/logging.py b/src/src/project_name/settings/logging.py deleted file mode 100644 index 3d91c9c..0000000 --- a/src/src/project_name/settings/logging.py +++ /dev/null @@ -1,28 +0,0 @@ -# A sample logging configuration. The only tangible logging -# performed by this configuration is to send an email to -# the site admins on every HTTP 500 error when DEBUG=False. -# See http://docs.djangoproject.com/en/dev/topics/logging for -# more details on how to customize your logging configuration. -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'filters': { - 'require_debug_false': { - '()': 'django.utils.log.RequireDebugFalse' - } - }, - 'handlers': { - 'mail_admins': { - 'level': 'ERROR', - 'filters': ['require_debug_false'], - 'class': 'django.utils.log.AdminEmailHandler' - } - }, - 'loggers': { - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, - } -} diff --git a/src/src/project_name/settings/middleware.py b/src/src/project_name/settings/middleware.py deleted file mode 100644 index 7f6ba73..0000000 --- a/src/src/project_name/settings/middleware.py +++ /dev/null @@ -1,15 +0,0 @@ - -MIDDLEWARE_CLASSES = [ - 'django.contrib.sessions.middleware.SessionMiddleware', - #'django.middleware.locale.LocaleMiddleware', - 'fnpdjango.middleware.URLLocaleMiddleware', - - 'django.middleware.common.CommonMiddleware', - 'django.middleware.csrf.CsrfViewMiddleware', - 'django.contrib.auth.middleware.AuthenticationMiddleware', - 'django_cas_ng.middleware.CASMiddleware', # Remove if not using CAS. - 'django.contrib.messages.middleware.MessageMiddleware', - # Uncomment the next line for simple clickjacking protection: - # 'django.middleware.clickjacking.XFrameOptionsMiddleware', - 'fnpdjango.middleware.SetRemoteAddrFromXRealIP' -] diff --git a/src/src/project_name/settings/paths.py b/src/src/project_name/settings/paths.py deleted file mode 100644 index 3b1a69e..0000000 --- a/src/src/project_name/settings/paths.py +++ /dev/null @@ -1,3 +0,0 @@ -from os import path - -PROJECT_DIR = path.dirname(path.dirname(path.dirname(path.abspath(path.dirname(__file__))))) diff --git a/src/src/project_name/settings/static.py b/src/src/project_name/settings/static.py deleted file mode 100644 index 32be508..0000000 --- a/src/src/project_name/settings/static.py +++ /dev/null @@ -1,40 +0,0 @@ -from os import path -from .paths import PROJECT_DIR - - -MEDIA_ROOT = path.join(PROJECT_DIR, 'var/media/') -MEDIA_URL = '/media/' -STATIC_ROOT = path.join(PROJECT_DIR, 'var/static/') -STATIC_URL = '/static/' - -STATICFILES_FINDERS = ( - 'django.contrib.staticfiles.finders.FileSystemFinder', - 'django.contrib.staticfiles.finders.AppDirectoriesFinder', -# 'django.contrib.staticfiles.finders.DefaultStorageFinder', -) - -STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage' -PIPELINE_CSS_COMPRESSOR = None -PIPELINE_JS_COMPRESSOR = None -PIPELINE_CSS = { - 'base': { - 'source_filenames': ( - 'css/base.scss', - ), - 'output_filename': 'compressed/base.css', - }, -} -PIPELINE_JS = { - 'base': { - 'source_filenames': ( - 'jquery.min.js', - ), - 'output_filename': 'compressed/base.js', - }, -} - -PIPELINE_COMPILERS = ( - 'pipeline.compilers.sass.SASSCompiler', -) - -PIPELINE_STORAGE = 'pipeline.storage.PipelineFinderStorage' diff --git a/src/src/project_name/settings/test.py b/src/src/project_name/settings/test.py new file mode 100644 index 0000000..e69de29 diff --git a/src/src/project_name/urls.py b/src/src/project_name/urls.py index 3303eb4..22d3c5b 100644 --- a/src/src/project_name/urls.py +++ b/src/src/project_name/urls.py @@ -1,27 +1,28 @@ -from django.conf.urls import patterns, include, url +from django.conf.urls import include, url from django.conf import settings from django.contrib import admin +import django_cas_ng.views -urlpatterns = patterns('', +urlpatterns = [ # Examples: - # url(r'^$', '{{ project_name }}.views.home', name='home'), + # url(r'^$', {{ project_name }}.views.home, name='home'), # url(r'^{{ project_name }}/', include('foo.urls')), - # Admin stuff. - url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), # CAS stuff. - url(r'^accounts/login/$', 'django_cas_ng.views.login'), - url(r'^accounts/logout/$', 'django_cas_ng.views.logout'), -) + url(r'^accounts/login/$', django_cas_ng.views.login), + url(r'^accounts/logout/$', django_cas_ng.views.logout), +] # Media in DEBUG mode if settings.DEBUG: - urlpatterns += patterns('', - url(r'^media/(?P.*)$', 'django.views.static.serve', { + from django.views.static import serve + urlpatterns += [ + url(r'^media/(?P.*)$', serve, { 'document_root': settings.MEDIA_ROOT, + 'show_indexes': True, }), - ) + ] diff --git a/src/src/project_name/wsgi.py b/src/src/project_name/wsgi.py index f768265..17539e6 100644 --- a/src/src/project_name/wsgi.py +++ b/src/src/project_name/wsgi.py @@ -1,32 +1,16 @@ """ WSGI config for {{ project_name }} project. -This module contains the WSGI application used by Django's development server -and any production WSGI deployments. It should expose a module-level variable -named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover -this application via the ``WSGI_APPLICATION`` setting. - -Usually you will have the standard Django WSGI application here, but it also -might make sense to replace the whole Django WSGI application with a custom one -that later delegates to the Django one. For example, you could introduce WSGI -middleware here, or combine a Django application with an application of another -framework. +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.8/howto/deployment/wsgi/ """ + 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" +from django.core.wsgi import get_wsgi_application + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{ project_name }}.settings") -# This application object is used by any WSGI server configured to use this -# file. This includes Django's development server, if the WSGI_APPLICATION -# setting points here. -from django.core.wsgi import get_wsgi_application application = get_wsgi_application() - -# Apply WSGI middleware here. -# from helloworld.wsgi import HelloWorldApplication -# application = HelloWorldApplication(application)