Browse files

Enhance the settings file, use PROJECT_DIR instead of hacking with en…

…vironment variables.
  • Loading branch information...
1 parent 3651330 commit cf2bc876c2a1b3d879806673f9ac4f16a09a741e @andrejtokarcik andrejtokarcik committed with dblado Aug 12, 2011
Showing with 26 additions and 45 deletions.
  1. +26 −45 wsgi/openshift/settings.py
View
71 wsgi/openshift/settings.py
@@ -1,46 +1,32 @@
+# -*- coding: utf-8 -*-
# Django settings for openshift project.
import os
-from re import search
+
+# a setting to determine whether we are running on OpenShift
+ON_OPENSHIFT = False
+if os.environ.has_key('OPENSHIFT_REPO_DIR'):
+ ON_OPENSHIFT = True
+
+PROJECT_DIR = os.path.dirname(os.path.realpath(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ADMINS = (
# ('Your Name', 'your_email@example.com'),
)
-
-# this snippet will determine if we are running on OpenShift
-ON_OPENSHIFT = False
-environ_keys = os.environ.keys()
-for key in environ_keys:
- if search("OPENSHIFT_REPO_DIR", key):
- ON_OPENSHIFT = True
-
MANAGERS = ADMINS
-if ON_OPENSHIFT:
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
- 'NAME': os.environ['OPENSHIFT_DATA_DIR'] + '/sqlite3.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.
- }
- }
-
-else:
- DATABASES = {
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': 'sqlite3.db',
- '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.
- }
+DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+ 'NAME': os.path.join(PROJECT_DIR, 'sqlite3.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.
}
+}
# Local time zone for this installation. Choices can be found here:
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
@@ -78,7 +64,7 @@
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
-STATIC_ROOT = ''
+STATIC_ROOT = os.path.join(PROJECT_DIR, '..', 'static')
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
@@ -101,7 +87,7 @@
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
-# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
+ #'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# Make this unique, and don't share it with anybody.
@@ -111,7 +97,7 @@
TEMPLATE_LOADERS = (
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
-# 'django.template.loaders.eggs.Loader',
+ #'django.template.loaders.eggs.Loader',
)
MIDDLEWARE_CLASSES = (
@@ -124,17 +110,12 @@
ROOT_URLCONF = 'openshift.urls'
-if ON_OPENSHIFT:
- 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.
- os.environ['OPENSHIFT_REPO_DIR'] + "/wsgi/openshift/templates"
- )
-else:
- TEMPLATE_DIRS = (
- os.environ['PWD'] + "/templates",
- )
+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.
+ os.path.join(PROJECT_DIR, 'templates'),
+)
INSTALLED_APPS = (
'django.contrib.auth',

0 comments on commit cf2bc87

Please sign in to comment.