Commits

Vincent Hillenbrink  committed e3a01df

Refactored settings and urls to etc package

  • Participants
  • Parent commits 7e52c53

Comments (0)

Files changed (21)

 distribute-*.tar.gz
 docs/_build
 externals/*
-logs/*.log
+log/*.log
 pip-log.txt
 PYSMELLTAGS
 PYSMELLTAGS.*

File db/.hgemptydir

Empty file added.

File etc/__init__.py

+"""
+Generic settings and url configuration for django-environments
+projects
+"""

File etc/settings/__init__.py

+from etc.settings.generic import *
+from etc.settings.database import *
+from etc.settings.log import *
+from etc.settings.middleware import *
+from etc.settings.template import *
+from etc.settings.apps.compressor import *

File etc/settings/apps/__init__.py

Empty file added.

File etc/settings/apps/compressor.py

+# Default settings for django-compressor
+# http://pypi.python.org/pypi/django_compressor
+# https://github.com/mintchaos/django_compressor
+
+COMPRESS = False
+#Default: the opposite of DEBUG
+"""Boolean that decides if compression will happen."""
+
+#COMPRESS_URL
+#Default: MEDIA_URL
+"""Controls the URL that linked media will be read from and compressed
+media will be written to."""
+
+#COMPRESS_ROOT
+#Default: MEDIA_ROOT
+"""Controls the absolute file path that linked media will be read
+from and compressed media will be written to."""
+
+COMPRESS_OUTPUT_DIR = 'z'
+#Default: 'CACHE'
+"""Controls the directory inside COMPRESS_ROOT that compressed files
+will be written to."""
+
+#COMPRESS_CSS_FILTERS
+#Default: ['compressor.filters.css_default.CssAbsoluteFilter']
+"""A list of filters that will be applied to CSS."""
+
+#COMPRESS_JS_FILTERS
+#Default: ['compressor.filters.jsmin.JSMinFilter']
+"""A list of filters that will be applied to javascript."""
+
+#COMPRESS_STORAGE
+#Default: 'compressor.storage.CompressorFileStorage'
+"""The dotted path to a Django Storage backend to be used to save the
+compressed files."""
+
+#COMPRESS_PARSER
+#Default: 'compressor.parser.BeautifulSoupParser'
+"""The backend to use when parsing the JavaScript or Stylesheet files.
+The backends included in compressor:
+* compressor.parser.BeautifulSoupParser
+* compressor.parser.LxmlParser
+See Dependencies for more info about the packages you need for
+each parser."""
+
+#COMPRESS_CACHE_BACKEND
+#Default: CACHE_BACKEND
+"""The backend to use for caching, in case you want to use a different
+cache backend for compressor. Defaults to the CACHE_BACKEND setting."""
+
+#COMPRESS_REBUILD_TIMEOUT
+#Default: 2592000 (30 days in seconds)
+"""The period of time after which the the compressed files are rebuilt
+even if no file changes are detected."""
+
+#COMPRESS_MINT_DELAY
+#Default: 30 (seconds)
+"""The upper bound on how long any compression should take to run.
+Prevents dog piling, should be a lot smaller than COMPRESS_REBUILD_TIMEOUT."""
+
+#COMPRESS_MTIME_DELAY
+#Default: None
+"""The amount of time (in seconds) to cache the result of the check
+of the modification timestamp of a file. Disabled by default. Should
+be smaller than COMPRESS_REBUILD_TIMEOUT and COMPRESS_MINT_DELAY."""

File etc/settings/database.py

+from os import path, environ
+
+from .generic import PROJECT_ROOT, DJANGO_PROJECT
+
+
+DATABASES_DEFAULT = {
+    'default_sqlite': {
+        'ENGINE': 'django.db.backends.sqlite3',
+        'NAME': path.join(PROJECT_ROOT, 'db', '%s.sqlite3' % DJANGO_PROJECT),
+    },
+    'default_mysql': {
+        'ENGINE': 'django.db.backends.mysql',
+        'NAME': DJANGO_PROJECT,
+        'USER': 'gjsb',
+    },
+    'default_postgres': {
+        'ENGINE': 'django.db.backends.postgresql_psycopg2',
+        'NAME': DJANGO_PROJECT,
+        'USER': 'gjsb',
+    }
+}
+
+DATABASES = {
+    'default': DATABASES_DEFAULT['default_' + environ.get('DJANGO_DATABASE_TYPE', 'sqlite')]
+}

File etc/settings/env/.hgemptydir

Empty file added.

File etc/settings/generic.py

+from os import environ, path
+
+
+PROJECT_ROOT = environ['PROJECT_ROOT']
+DJANGO_PROJECT = environ['DJANGO_PROJECT']
+DJANGO_PROJECT_DIR = path.join(PROJECT_ROOT, DJANGO_PROJECT)
+
+LOCAL_SERVER_PORT = 8001
+
+ADMINS = (
+    ('g0j0admin', 'admin@g0j0.com'),
+)
+SERVER_EMAIL = ADMINS[0][1]
+MANAGERS = ADMINS
+
+DEFAULT_FROM_EMAIL = 'Goeie Jongens <%s>' % ADMINS[0][1]
+
+DEBUG = False
+TEMPLATE_DEBUG = DEBUG
+
+TIME_ZONE = 'Europe/Amsterdam'
+
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+USE_I18N = False
+USE_L10N = False
+
+SERVE_DOCS = False
+SERVE_MEDIA = False
+MEDIA_ID = 'static'
+MEDIA_ROOT = path.join(DJANGO_PROJECT_DIR, MEDIA_ID)
+MEDIA_URL = '/%s/' % MEDIA_ID
+ADMIN_MEDIA_PREFIX = '/adminmedia/'
+
+ROOT_URLCONF = DJANGO_PROJECT + '.urls'
+
+FIXTURE_DIRS = (
+)
+
+CACHE_BACKEND = 'dummy:///'

File etc/settings/log.py

+from os import path
+import logging
+
+from .generic import PROJECT_ROOT, DJANGO_PROJECT
+
+
+LOGGING_FILENAME = path.join(PROJECT_ROOT, 'log/%s.log' % DJANGO_PROJECT)
+
+logging.basicConfig(
+    level=logging.DEBUG,
+    format='%(asctime)s - %(name)-30s - %(levelname)-8s: %(message)s',
+    #format='%(name)s: %(message)s',
+    #datefmt='%a, %d %b %Y %H:%M:%S',
+    filename=LOGGING_FILENAME,
+)

File etc/settings/middleware.py

+MIDDLEWARE_CLASSES_DEFAULT = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.middleware.csrf.CsrfViewMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+    'django.contrib.messages.middleware.MessageMiddleware',
+)
+
+MIDDLEWARE_CLASSES = MIDDLEWARE_CLASSES_DEFAULT

File etc/settings/template.py

+from os import path
+
+from .generic import DJANGO_PROJECT_DIR
+
+
+TEMPLATE_DIRS = (
+)
+
+TEMPLATE_LOADERS_DEFAULT = (
+    'django.template.loaders.filesystem.Loader',
+    'django.template.loaders.app_directories.Loader',
+)
+
+TEMPLATE_LOADERS = TEMPLATE_LOADERS_DEFAULT
+
+TEMPLATE_CONTEXT_PROCESSORS_DEFAULT = (
+    '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 1.3
+    'django.contrib.messages.context_processors.messages',
+)
+
+TEMPLATE_CONTEXT_PROCESSORS = TEMPLATE_CONTEXT_PROCESSORS_DEFAULT
+from django.conf.urls.defaults import patterns, include, url, handler404, handler500
+handler404, handler500 # Keep pyflakes happy...
+from django.contrib import admin
+from django.contrib import databrowse
+from django.conf import settings
+
+
+__all__ = ('handler404', 'handler500', 'patterns', 'default_patterns', 'databrowse')
+
+
+admin.autodiscover()
+
+
+default_patterns = patterns('',
+    (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+    (r'^admin/', include(admin.site.urls)),
+    (r'^databrowse/(.*)', databrowse.site.root),
+)
+
+default_patterns += patterns('django.views.generic.simple',
+    ('^$', 'redirect_to', {'url': '/admin/'}),
+)
+
+if settings.SERVE_MEDIA:
+    default_patterns += patterns('',
+        (r'^%s/(?P<path>.*)$' % settings.MEDIA_ID, 'django.views.static.serve',
+         {'document_root': settings.MEDIA_ROOT, 'show_indexes': False}),
+    )

File log/.hgemptydir

Empty file added.

File mysite/settings/env/development.py

 from .. import *
-from os import path
 
 
-DATABASE_ENGINE = 'sqlite3'
-DATABASE_HOST = ''
-DATABASE_NAME = ''
-DATABASE_USER = ''
-DATABASE_PASSWORD = ''
-
 DEBUG = True
 
 SERVE_MEDIA = True
 
+INSTALLED_APPS += (
+    'django.contrib.databrowse',
+    #'debug_toolbar',
+    #'devserver',
+    #'django_extensions',
+)
+
 COMPRESS = False
 
 SEND_BROKEN_LINK_EMAILS = False

File mysite/settings/env/production_en.py

 from production_generic import *
 
+
 # Just set the language
 LANGUAGE_CODE = 'en'

File mysite/settings/env/production_generic.py

 from .. import *
-from os import path
 
 
-DATABASE_ENGINE = 'postgresql'
-DATABASE_HOST = ''
-DATABASE_NAME = ''
-DATABASE_USER = ''
-DATABASE_PASSWORD = ''
-
 DEBUG = False
 
 SERVE_MEDIA = False
 CACHE_MIDDLEWARE_SECONDS = 86400
 CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
 
+from os import path
+
 try:
     CACHE_MIDDLEWARE_KEY_PREFIX += '.' + path.basename(__file__).split('.')[0]
 except NameError:

File mysite/settings/env/staging.py

 from .. import *
-from os import path
 
 
-DATABASE_ENGINE = 'postgresql'
-DATABASE_HOST = ''
-DATABASE_NAME = ''
-DATABASE_USER = ''
-DATABASE_PASSWORD = ''
-
 DEBUG = False
 
 SERVE_MEDIA = False
 CACHE_MIDDLEWARE_SECONDS = 60
 CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
 
+from os import path
+
 try:
     CACHE_MIDDLEWARE_KEY_PREFIX += '.' + path.basename(__file__).split('.')[0]
 except NameError:

File mysite/settings/generic.py

-from os import path
-import logging
+from etc.settings import *
 
 
-DJANGO_PROJECT_DIR = path.dirname(path.dirname(path.abspath(__file__)))
-DJANGO_PROJECT = path.basename(DJANGO_PROJECT_DIR)
-PROJECT_ROOT = path.dirname(DJANGO_PROJECT_DIR)
-
-LOGGING_FILENAME = path.join(PROJECT_ROOT, 'log/mysite.log')
-
-logging.basicConfig(
-    level=logging.DEBUG,
-    format='%(asctime)s - %(name)s - %(levelname)s: %(message)s',
-    # format='%(name)s: %(message)s',
-    #filename=LOGGING_FILENAME,
-)
-
-DEBUG = False
-TEMPLATE_DEBUG = DEBUG
-
 LOCAL_SERVER_PORT = 7000
 
-ADMINS = (
-    # ('Your Name', 'your_email@domain.com'),
-)
-
-MANAGERS = ADMINS
-
-DATABASE_ENGINE = ''           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-DATABASE_NAME = ''             # Or path to database file if using sqlite3.
-DATABASE_USER = ''             # Not used with sqlite3.
-DATABASE_PASSWORD = ''         # Not used with sqlite3.
-DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
-DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
-
-CACHE_BACKEND = 'dummy://'
-CACHE_MIDDLEWARE_KEY_PREFIX = 'mysite'
-CACHE_MIDDLEWARE_SECONDS = 600
-CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True
-
-
-# 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 = 'Europe/Amsterdam'
-
-# Language code for this installation. All choices can be found here:
-# http://www.i18nguy.com/unicode/language-identifiers.html
-LANGUAGE_CODE = 'en-us'
-
-SITE_ID = 1
-
-# 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
-
-# Whether we serve static content via Django (to be overruled in local settings)
-SERVE_MEDIA = False
-
-# Absolute path to the directory that holds media.
-# Example: "/home/media/media.lawrence.com/"
-MEDIA_ROOT = path.join(PROJECT_ROOT, 'static')
-
-# URL that handles the media served from MEDIA_ROOT. Make sure to use a
-# trailing slash if there is a path component (optional in other cases).
-# Examples: "http://media.lawrence.com", "http://example.com/media/"
-MEDIA_URL = '/static/'
-
-# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
-# trailing slash.
-# Examples: "http://foo.com/media/", "/media/".
-ADMIN_MEDIA_PREFIX = '/adminmedia/'
-
-# Make this unique, and don't share it with anybody.
 SECRET_KEY = '8se!xv-_5+fq6!##&z0p5cje0o)!rvb^ph50v1#7v)l=c1*vin'
 
-# List of callables that know how to import templates from various sources.
-TEMPLATE_LOADERS = (
-    'django.template.loaders.filesystem.load_template_source',
-    'django.template.loaders.app_directories.load_template_source',
-)
-
-TEMPLATE_CONTEXT_PROCESSORS = (
-        "django.core.context_processors.auth",
-        "django.core.context_processors.i18n",
-        "django.core.context_processors.request",
-        "django.core.context_processors.media",
-)
-
-MIDDLEWARE_CLASSES = (
-    'django.middleware.common.CommonMiddleware',
-    'django.contrib.sessions.middleware.SessionMiddleware',
-    'django.contrib.auth.middleware.AuthenticationMiddleware',
-    'django.middleware.doc.XViewMiddleware',
-    )
-
-ROOT_URLCONF = 'mysite.urls'
-
-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.
-    #path.join(DJANGO_PROJECT, 'templates'),
-)
-
-FIXTURE_DIRS = (
-    #path.join(DJANGO_PROJECT, 'fixtures'),
-)
-
 INSTALLED_APPS = (
     'django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.sites',
+    'django.contrib.messages',
     'django.contrib.admin',
     'django.contrib.admindocs',
 )

File mysite/static/index.html

+It works!

File mysite/urls.py

-from django.conf.urls.defaults import *
-from django.contrib import admin
-from django.conf import settings
+from etc.urls import *
 
-admin.autodiscover()
 
-# Basic stuff
-urlpatterns = patterns('',
-    (r'^', Just_throwing_exception_to_get_the_debug_screen),
-
-    #(r'^', include('main.urls')),
-
-    #$(r'^admin/doc/', include('django.contrib.admindocs.urls')),
-    #(r'^admin/', include(admin.site.urls)),
-
-    #$(r'^admin/filebrowser/', include('filebrowser.urls')),
-    #$(r'^admin/rosetta/', include('rosetta.urls')),
-)
-
-# Check SERVE_MEDIA
-if settings.SERVE_MEDIA:
-    urlpatterns += patterns('',
-        (r'^static/(?P<path>.*)$', 'django.views.static.serve',
-         {'document_root': settings.MEDIA_ROOT, 'show_indexes': False}),
-    )
+urlpatterns = default_patterns