Skip to content

Instantly share code, notes, and snippets.

@airtonix
Created December 25, 2011 11:48
Show Gist options
  • Save airtonix/1519138 to your computer and use it in GitHub Desktop.
Save airtonix/1519138 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
"""
# Simple Website Settings
There a few settings that require the config/settings.cfg file to contain
data.
Search through this file for getconfig to find out the relevant
config sections and key/values.
these will be prefixed with the current mode. see the config/settings.cfg
for more information.
"""
import os
import sys
import ConfigParser
from base.lib.cms_templates import list_templates
from base.lib.config import (
getconfig,
hasconfig,
PROJECT_CONFIG,
MODE
)
_ = lambda x: x
DEBUG=True
HEREPATH=os.path.realpath(os.path.dirname(__file__))
PROJECT_ROOT = os.path.realpath(
os.path.dirname(HEREPATH),
)
PROJECT_DIR = PROJECT_ROOT
SITE_ROOT = os.path.realpath(
os.path.dirname(PROJECT_ROOT),
)
PROJECT_MODE = None
if "PROJECT_MODE" in os.environ.keys():
PROJECT_MODE = os.environ['PROJECT_MODE']
else:
PROJECT_MODE = MODE.get('project', 'mode')
import logging as logger
logger.basicConfig(filename= os.path.join(
SITE_ROOT, 'logs', 'project.settings.log'), level=logger.ERROR)
logger.debug("SITE_ROOT: {0}".format(SITE_ROOT))
logger.debug("HEREPATH: {0}".format(HEREPATH))
logger.debug("PROJECT_ROOT: {0}".format(PROJECT_ROOT))
#
# ConfigParser Wrappers
#
PROJECT_NAME = getconfig('django', 'project')
PROJECT_DOMAIN = getconfig('django', 'domain_name')
#
# Modularised Settings
#
for settings_file in os.listdir(HEREPATH):
file_name, file_ext = os.path.splitext(settings_file)
if file_ext == ".py" and not "__" in file_name :
try:
logger.debug("Importing settings.{0}".format(file_name))
exec("from {0} import *".format(file_name)) in globals()
except ImportError:
logger.error("Problem importing settings.{0}".format(file_name))
pass
#
# Dynamic Secret Key
#
try:
from key import *
logger.debug("Imported secret key")
except ImportError:
logger.debug("Secret Key missing, generating")
from hashlib import sha1
from base.lib.generate_key import generate_key
secret_key_file = open(os.path.join(HEREPATH, "key.py"), "w")
secret_key_file.write("""secret_key="{0}" """.format(
generate_key(40, 128, digester=sha1)))
secret_key_file.close()
from key import *
logger.debug("Generated & Imported Secret Key")
#
#
#
##
# Django settings for project project.
DEBUG = True
TEMPLATE_DEBUG = DEBUG
EMAIL_HOST = getconfig('emailserver', 'host')
EMAIL_HOST_USER = getconfig('emailserver', 'username')
EMAIL_HOST_PASSWORD = getconfig('emailserver', 'password')
EMAIL_PORT = getconfig('emailserver', 'port')
EMAIL_SUBJECT_PREFIX = getconfig('emailserver', 'subject-prefix')
EMAIL_USE_TLS = getconfig('emailserver', 'use-tls')
RECIPIENT_LIST = getconfig('emailcontacts', 'recipient_list')
DEFAULT_FROM_EMAIL = getconfig('emailcontacts', "default_from")
SERVER_EMAIL = getconfig('emailcontacts', "developers")
ADMINS = (
(
getconfig('emailcontacts', 'admin_name'),
getconfig('emailcontacts', 'admin_email'),
),
)
MANAGERS = ADMINS
ADMINS = (
('YourName', 'developers@hostname.tld'),
)
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(SITE_ROOT, 'db', 'database.sqlite3'),
# Not used with sqlite3.
'USER': '',
# Not used with sqlite3.
'PASSWORD': '',
# Set to empty string for localhost. Not used with sqlite3.
'HOST': '',
# Set to empty string for default. Not used with sqlite3.
'PORT': '',
}
}
TIME_ZONE = getconfig('django', 'timezone')
SITE_ID = 1
USE_I18N = True
USE_L10N = False
LANGUAGE_CODE=getconfig('django', 'language_code')
#
# Google Analytics
#
GOOGLE_ANALYTICS_MODEL = True
#
# Resources
#
MEDIA_ROOT = os.path.join(SITE_ROOT, "files")
logger.debug("MEDIA_ROOT: {0}".format(MEDIA_ROOT))
MEDIA_URL = getconfig('django', "files")
logger.debug("MEDIA_URL: {0}".format(MEDIA_URL))
STATIC_ROOT = os.path.join(SITE_ROOT, "static")
logger.debug("STATIC_ROOT: {0}".format(STATIC_ROOT))
STATIC_URL = getconfig('django', "static")
logger.debug("STATIC_URL: {0}".format(STATIC_URL))
ADMIN_MEDIA_PREFIX = '{0}admin/'.format(STATIC_URL)
# Additional locations of static files
STATICFILES_DIRS = (
)
# List of finder classes that know how to find static files in
# various locations.
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
# 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',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
# 'django.core.context_processors.i18n',
'django.core.context_processors.request',
'django.core.context_processors.media',
'django.core.context_processors.static',
)
TEMPLATE_CONTEXT_PROCESSORS += (
'base.context_processors.current_site',
'base.context_processors.staticfiles',
'base.context_processors.mediafiles',
'base.context_processors.adminmedia',
)
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
)
ROOT_URLCONF = 'project.urls'
TEMPLATE_DIRS = (
)
SITEMAP_PING_URLS=None
ping_urls = getconfig('django', 'ping-urls')
if ping_urls:
SITEMAP_PING_URLS = [pingurl.strip() for pingurl in ping_urls.split(",")]
CURRENT_SITE_DOMAIN_USE_REQUEST_LOCATION=True
#
# Django User Profiles
#
AUTH_PROFILE_MODULE = 'account.UserProfile'
LOGIN_URL = "/account/login"
#
# DjangoCMS
#
CMS_PLUGIN_CONTEXT_PROCESSORS = []
CMS_PLUGIN_PROCESSORS = []
CMS_APPHOOKS = []
PLACEHOLDER_FRONTEND_EDITING = True
CMS_HIDE_UNTRANSLATED = True
CMS_MEDIA_PATH = "/cms/"
CMS_MEDIA_ROOT = os.path.join(SITE_ROOT, "static", "cms")
CMS_MEDIA_URL = "{0}/cms/".format(MEDIA_URL)
CMS_URL_OVERWRITE = False
CMS_MENU_TITLE_OVERWRITE = True
CMS_REDIRECTS = False
CMS_DBGETTEXT = False
CMS_SEO_FIELDS=True
CMS_USE_TINYMCE = True
CMS_LANGUAGE_REDIRECT=False
TINYMCE_DEFAULT_CONFIG = {
'plugins': "table, spellchecker, paste, searchreplace, template",
'theme': "advanced",
'theme_advanced_buttons2_add': "template",
# this configuration relies on our urls and views in project.base
'template_external_list_url': '/tiny-mce/templates.js',
'theme_advanced_statusbar_location': 'bottom',
'theme_advanced_path': False,
'theme_advanced_resizing': True,
'theme_advanced_resize_horizontal': False,
'theme_advanced_resizing_use_cookie': True,
'extended_valid_elements': "footer, section, chapter, header, page",
'template_cdate_classes': "cdate creationdate",
'template_mdate_classes': "mdate modifieddate",
'template_selected_content_classes': "selcontent",
'template_cdate_format': "%m/%d/%Y: %H:%M:%S",
'template_mdate_format': "%m/%d/%Y: %H:%M:%S",
'accessibility_usage_title': "Some Useful Title",
}
MIDDLEWARE_CLASSES += (
# 'cms.middleware.multilingual.MultilingualURLMiddleware',
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.user.CurrentUserMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
)
TEMPLATE_CONTEXT_PROCESSORS += (
'cms.context_processors.media',
'sekizai.context_processors.sekizai',
)
#
# This gathers all the layout templates together
#
# list all your cms layout collections under the CMS section in config/website.cfg
CMS_LAYOUT_PATH = getconfig('cms', 'templates').split(",")
logger.info("CMS_LAYOUT_PATH : {0}".format(CMS_LAYOUT_PATH))
CMS_TEMPLATES = list();
for path in CMS_LAYOUT_PATH :
layout_path = os.path.join(PROJECT_ROOT, path)
if os.path.exists(layout_path):
template_list = list_templates( layout_path );
logger.error("{0} : {1}".format(layout_path, template_list))
CMS_TEMPLATES += template_list
##
#
# Event & Message Logging
#
LOGGING = {
'version': 1,
"loggers" : {
"root" : {
'level' : 'DEBUG',
'handlers' : ('console', ),
'qualname' : 'root',
},
"main" : {
'level' : 'DEBUG',
'handlers' : ('main', ),
'qualname' : 'main',
},
"feedback" : {
'level' : 'DEBUG',
'handlers' : ('feedback', ),
'qualname' : 'feedback',
},
"shop" : {
'level' : 'DEBUG',
'handlers' : ('shop', ),
'qualname' : 'shop',
},
"importer" : {
'level' : 'INFO',
'handlers' : ('importer', ),
'qualname' : 'importer',
},
},
"handlers" : {
'console' : {
'class' : 'logging.StreamHandler',
'level' : 'DEBUG',
'formatter' : 'simpleFormatter',
'stream' : (sys.stdout, ),
},
'main' : {
'class':'logging.handlers.RotatingFileHandler',
'maxBytes': 20480,
'backupCount': 1,
'level' : 'DEBUG',
'formatter' : 'simpleFormatter',
'filename' : os.path.join(SITE_ROOT, "logs", "main.log"),
},
'feedback' : {
'class':'logging.handlers.RotatingFileHandler',
'filename' : os.path.join(SITE_ROOT, "logs", "feedback.log"),
'maxBytes': 20480,
'backupCount': 3,
'level' : 'DEBUG',
'formatter' : 'simpleFormatter',
},
'shop' : {
'class':'logging.handlers.RotatingFileHandler',
'filename' : os.path.join(SITE_ROOT, "logs", "shop.log"),
'maxBytes': 20480,
'backupCount': 3,
'level' : 'DEBUG',
'formatter' : 'simpleFormatter',
},
'importer' : {
'class':'logging.handlers.RotatingFileHandler',
'filename' : os.path.join(SITE_ROOT, "logs", "importer.log"),
'maxBytes': 20480,
'backupCount': 3,
'level' : 'DEBUG',
'formatter' : 'simpleFormatter',
},
},
"formatters" : {
'simpleFormatter' : {
'format' : '%(asctime)s - %(levelname)s - %(filename)s:%(funcName)s:%(lineno)d - %(message)s',
}
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment