From 80ba329d2987a0b2346ecc165eae286b81449153 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Thu, 25 Dec 2014 16:00:28 +0100 Subject: [PATCH] initial working settings --- gvafile/gvafile/settings.py | 82 -------- gvafile/gvafile/settings/__init__.py | 3 + gvafile/gvafile/settings/base.py | 281 +++++++++++++++++++++++++ gvafile/gvafile/settings/local.py | 51 +++++ gvafile/gvafile/settings/production.py | 50 +++++ gvafile/gvafile/settings/test.py | 20 ++ gvafile/gvafile/urls.py | 25 ++- gvafile/osusers/__init__.py | 3 + gvafile/osusers/models.py | 3 + 9 files changed, 430 insertions(+), 88 deletions(-) delete mode 100644 gvafile/gvafile/settings.py create mode 100644 gvafile/gvafile/settings/__init__.py create mode 100644 gvafile/gvafile/settings/base.py create mode 100644 gvafile/gvafile/settings/local.py create mode 100644 gvafile/gvafile/settings/production.py create mode 100644 gvafile/gvafile/settings/test.py create mode 100644 gvafile/osusers/__init__.py create mode 100644 gvafile/osusers/models.py diff --git a/gvafile/gvafile/settings.py b/gvafile/gvafile/settings.py deleted file mode 100644 index aebc357..0000000 --- a/gvafile/gvafile/settings.py +++ /dev/null @@ -1,82 +0,0 @@ -""" -Django settings for gvafile project. - -For more information on this file, see -https://docs.djangoproject.com/en/1.6/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/1.6/ref/settings/ -""" - -# Build paths inside the project like this: os.path.join(BASE_DIR, ...) -import os -BASE_DIR = os.path.dirname(os.path.dirname(__file__)) - - -# Quick-start development settings - unsuitable for production -# See https://docs.djangoproject.com/en/1.6/howto/deployment/checklist/ - -# SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = 'y#njre^k%h0jvpe0b1p$44sbg5d7lg%9m#kz08v+$%+)ur5*@o' - -# SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True - -TEMPLATE_DEBUG = True - -ALLOWED_HOSTS = [] - - -# Application definition - -INSTALLED_APPS = ( - 'django.contrib.admin', - 'django.contrib.auth', - 'django.contrib.contenttypes', - 'django.contrib.sessions', - 'django.contrib.messages', - 'django.contrib.staticfiles', -) - -MIDDLEWARE_CLASSES = ( - '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', -) - -ROOT_URLCONF = 'gvafile.urls' - -WSGI_APPLICATION = 'gvafile.wsgi.application' - - -# Database -# https://docs.djangoproject.com/en/1.6/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), - } -} - -# Internationalization -# https://docs.djangoproject.com/en/1.6/topics/i18n/ - -LANGUAGE_CODE = 'en-us' - -TIME_ZONE = 'UTC' - -USE_I18N = True - -USE_L10N = True - -USE_TZ = True - - -# Static files (CSS, JavaScript, Images) -# https://docs.djangoproject.com/en/1.6/howto/static-files/ - -STATIC_URL = '/static/' diff --git a/gvafile/gvafile/settings/__init__.py b/gvafile/gvafile/settings/__init__.py new file mode 100644 index 0000000..4f53a5e --- /dev/null +++ b/gvafile/gvafile/settings/__init__.py @@ -0,0 +1,3 @@ +""" +This module contains settings for various environments. +""" diff --git a/gvafile/gvafile/settings/base.py b/gvafile/gvafile/settings/base.py new file mode 100644 index 0000000..470a9cf --- /dev/null +++ b/gvafile/gvafile/settings/base.py @@ -0,0 +1,281 @@ +# -*- coding: utf-8 -*- +# pymode:lint_ignore=E501 +""" +Common settings and globals. + +""" + +from os.path import abspath, basename, dirname, join, normpath +from sys import path +from os import environ + +# Normally you should not import ANYTHING from Django directly +# into your settings, but ImproperlyConfigured is an exception. +from django.core.exceptions import ImproperlyConfigured + + +def get_env_setting(setting): + """ + Get the environment setting or return exception. + + :param str setting: name of an environment setting + :raises ImproperlyConfigured: if the environment setting is not defined + :return: environment setting value + :rtype: str + """ + try: + return environ[setting] + except KeyError: + error_msg = "Set the %s env variable" % setting + raise ImproperlyConfigured(error_msg) + + +########## PATH CONFIGURATION +# Absolute filesystem path to the Django project directory: +DJANGO_ROOT = dirname(dirname(abspath(__file__))) + +# Absolute filesystem path to the top-level project folder: +SITE_ROOT = dirname(DJANGO_ROOT) + +# Site name: +SITE_NAME = basename(DJANGO_ROOT) + +# Add our project to our pythonpath, this way we don't need to type our project +# name in our dotted import paths: +path.append(DJANGO_ROOT) +########## END PATH CONFIGURATION + + +########## DEBUG CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug +DEBUG = False + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug +TEMPLATE_DEBUG = DEBUG +########## END DEBUG CONFIGURATION + + +########## MANAGER CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#admins +ADMINS = ( + (get_env_setting('GVAFILE_ADMIN_NAME'), get_env_setting('GVAFILE_ADMIN_EMAIL')), +) + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#managers +MANAGERS = ADMINS +########## END MANAGER CONFIGURATION + + +########## DATABASE CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#databases +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': normpath(join(DJANGO_ROOT, 'default.db')), + 'USER': '', + 'PASSWORD': '', + 'HOST': '', + 'PORT': '', + }, +} +########## END DATABASE CONFIGURATION + + +########## GENERAL CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#time-zone +TIME_ZONE = 'Europe/Berlin' + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#language-code +LANGUAGE_CODE = 'en-us' + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#site-id +SITE_ID = 1 + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-i18n +USE_I18N = True + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-l10n +USE_L10N = True + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#use-tz +USE_TZ = True +########## END GENERAL CONFIGURATION + + +########## MEDIA CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-root +MEDIA_ROOT = normpath(join(SITE_ROOT, 'media')) + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#media-url +MEDIA_URL = '/media/' +########## END MEDIA CONFIGURATION + + +########## STATIC FILE CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root +STATIC_ROOT = normpath(join(SITE_ROOT, 'assets')) + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url +STATIC_URL = '/static/' + +# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS +STATICFILES_DIRS = ( + normpath(join(SITE_ROOT, 'static')), +) + +# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', +) +########## END STATIC FILE CONFIGURATION + + +########## SECRET CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#secret-key +# Note: This key should only be used for development and testing. +SECRET_KEY = get_env_setting('GVAFILE_SECRETKEY') +########## END SECRET CONFIGURATION + + +########## SITE CONFIGURATION +# Hosts/domain names that are valid for this site +# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts +ALLOWED_HOSTS = [] +########## END SITE CONFIGURATION + + +########## FIXTURE CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#std:setting-FIXTURE_DIRS +FIXTURE_DIRS = ( + normpath(join(SITE_ROOT, 'fixtures')), +) +########## END FIXTURE CONFIGURATION + + +########## TEMPLATE CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-context-processors +TEMPLATE_CONTEXT_PROCESSORS = ( + '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', +) + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-loaders +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', +) + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-dirs +TEMPLATE_DIRS = ( + normpath(join(SITE_ROOT, 'templates')), +) +########## END TEMPLATE CONFIGURATION + + +########## MIDDLEWARE CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#middleware-classes +MIDDLEWARE_CLASSES = ( + # Default Django middleware. + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +) +########## END MIDDLEWARE CONFIGURATION + + +########## URL CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#root-urlconf +ROOT_URLCONF = '%s.urls' % SITE_NAME +########## END URL CONFIGURATION + + +########## TEST RUNNER CONFIGURATION +TEST_RUNNER = 'django.test.runner.DiscoverRunner' +########## END TEST RUNNER CONFIGURATION + + +########## APP CONFIGURATION +DJANGO_APPS = ( + # Default Django apps: + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + # Useful template tags: + # 'django.contrib.humanize', + + # Admin panel and documentation: + 'django.contrib.admin', + # 'django.contrib.admindocs', +) + +# Apps specific for this project go here. +LOCAL_APPS = ( + 'osusers', +) + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#installed-apps +INSTALLED_APPS = DJANGO_APPS + LOCAL_APPS +########## END APP CONFIGURATION + + +########## LOGGING CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#logging +# 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, + }, + } +} +########## END LOGGING CONFIGURATION + + +########## WSGI CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#wsgi-application +WSGI_APPLICATION = '%s.wsgi.application' % SITE_NAME +########## END WSGI CONFIGURATION + + +########## CELERY CONFIGURATION +BROKER_URL = get_env_setting('GVAFILE_BROKER_URL') +CELERY_RESULT_BACKEND = 'amqp' +CELERY_RESULT_PERSISTENT = True +CELERY_TASK_RESULT_EXPIRES = None +CELERY_ACCEPT_CONTENT = ['yaml'] +CELERY_RESULT_SERIALIZER = 'yaml' +########## END CELERY CONFIGURATION diff --git a/gvafile/gvafile/settings/local.py b/gvafile/gvafile/settings/local.py new file mode 100644 index 0000000..dbd4381 --- /dev/null +++ b/gvafile/gvafile/settings/local.py @@ -0,0 +1,51 @@ +# pymode:lint_ignore=W0401,E501 +""" +Development settings and globals based on :py:mod:`gvafile.settings.base`. + +""" + +from __future__ import absolute_import + +from .base import * + + +########## DEBUG CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#debug +DEBUG = True + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#template-debug +TEMPLATE_DEBUG = DEBUG +########## END DEBUG CONFIGURATION + + +########## EMAIL CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend +EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' +########## END EMAIL CONFIGURATION + + +########## CACHE CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches +CACHES = { + 'default': { + 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache', + } +} +########## END CACHE CONFIGURATION + + +########## TOOLBAR CONFIGURATION +# See: http://django-debug-toolbar.readthedocs.org/en/latest/installation.html#explicit-setup +INSTALLED_APPS += ( + 'debug_toolbar', +) + +MIDDLEWARE_CLASSES += ( + 'debug_toolbar.middleware.DebugToolbarMiddleware', +) + +DEBUG_TOOLBAR_PATCH_SETTINGS = False + +# http://django-debug-toolbar.readthedocs.org/en/latest/installation.html +INTERNAL_IPS = ('127.0.0.1',) +########## END TOOLBAR CONFIGURATION diff --git a/gvafile/gvafile/settings/production.py b/gvafile/gvafile/settings/production.py new file mode 100644 index 0000000..4419785 --- /dev/null +++ b/gvafile/gvafile/settings/production.py @@ -0,0 +1,50 @@ +# pymode:lint_ignore=W0401,E501 +""" +Production settings and globals based on :py:mod:`gvafile.settings.base`. + +""" + +from __future__ import absolute_import + +from .base import * + +########## HOST CONFIGURATION +# See: https://docs.djangoproject.com/en/1.5/releases/1.5/#allowed-hosts-required-in-production +ALLOWED_HOSTS = get_env_setting('GVAFILE_ALLOWED_HOSTS').split(',') +########## END HOST CONFIGURATION + +########## EMAIL CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-backend +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host +#EMAIL_HOST = environ.get('EMAIL_HOST', 'smtp.gmail.com') + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-password +#EMAIL_HOST_PASSWORD = environ.get('EMAIL_HOST_PASSWORD', '') + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-host-user +#EMAIL_HOST_USER = environ.get('EMAIL_HOST_USER', 'your_email@example.com') + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-port +#EMAIL_PORT = environ.get('EMAIL_PORT', 587) + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-subject-prefix +EMAIL_SUBJECT_PREFIX = '[%s] ' % SITE_NAME + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#email-use-tls +#EMAIL_USE_TLS = True + +# See: https://docs.djangoproject.com/en/dev/ref/settings/#server-email +SERVER_EMAIL = get_env_setting('GVAFILE_SERVER_EMAIL') +########## END EMAIL CONFIGURATION + +########## DATABASE CONFIGURATION +#DATABASES = {} +########## END DATABASE CONFIGURATION + + +########## CACHE CONFIGURATION +# See: https://docs.djangoproject.com/en/dev/ref/settings/#caches +#CACHES = {} +########## END CACHE CONFIGURATION diff --git a/gvafile/gvafile/settings/test.py b/gvafile/gvafile/settings/test.py new file mode 100644 index 0000000..a132e85 --- /dev/null +++ b/gvafile/gvafile/settings/test.py @@ -0,0 +1,20 @@ +# pymode:lint_ignore=W0401 +""" +Test settings based on :py:mod:`gvafile.settings.base`. + +""" +from __future__ import absolute_import + +from .base import * + +########## IN-MEMORY TEST DATABASE +DATABASES = { + "default": { + "ENGINE": "django.db.backends.sqlite3", + "NAME": ":memory:", + "USER": "", + "PASSWORD": "", + "HOST": "", + "PORT": "", + }, +} diff --git a/gvafile/gvafile/urls.py b/gvafile/gvafile/urls.py index 3c9d9a1..ca59fb7 100644 --- a/gvafile/gvafile/urls.py +++ b/gvafile/gvafile/urls.py @@ -1,12 +1,25 @@ -from django.conf.urls import patterns, include, url +""" +This module defines the main URLConf for gvaldap. +""" + +from django.conf.urls import patterns, include, url +from django.conf import settings + +# Uncomment the next two lines to enable the admin: from django.contrib import admin admin.autodiscover() -urlpatterns = patterns('', - # Examples: - # url(r'^$', 'gvafile.views.home', name='home'), - # url(r'^blog/', include('blog.urls')), - +urlpatterns = patterns( + '', url(r'^admin/', include(admin.site.urls)), ) + +# Uncomment the next line to serve media files in dev. +# urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + +if settings.DEBUG: + import debug_toolbar + urlpatterns += patterns('', + url(r'^__debug__/', include(debug_toolbar.urls)), + ) diff --git a/gvafile/osusers/__init__.py b/gvafile/osusers/__init__.py new file mode 100644 index 0000000..b960717 --- /dev/null +++ b/gvafile/osusers/__init__.py @@ -0,0 +1,3 @@ +""" +This module contains :py:mod:`osusers.tasks`. +""" diff --git a/gvafile/osusers/models.py b/gvafile/osusers/models.py new file mode 100644 index 0000000..d1ff455 --- /dev/null +++ b/gvafile/osusers/models.py @@ -0,0 +1,3 @@ +""" +Empty models module required for Django to accept this as an app. +"""