import os
import logging
import re
from cog.utils import str2bool

rel = lambda *x: os.path.join(os.path.abspath(os.path.dirname(__file__)), *x)

ESGF_CONF_DIR = os.getenv('ESGF_CONF_DIR', rel(''))

''' 
SITE SPECIFIC CONFIGURATION
These parameters are read from file 'cog_settings.cfg' 
located in directory COG_CONFIG_DIR (or by default '/usr/local/cog/cog_config').
Each parameter has a default value.
'''
CSRF_COOKIE_SECURE = False
SESSION_COOKIE_SECURE = False
from cog.constants import SECTION_ESGF, SECTION_PID
ESGF_CONFIG = True
SITE_NAME = "Local CoG" 
SITE_DOMAIN = "localhost:8000"
TIME_ZONE = 'America/Denver'
COG_MAILING_LIST = '<EMAIL>'
SECRET_KEY = '<KEY>
# for SQLLite back-end
DATABASE_PATH = ESGF_CONF_DIR + "django.data"
# for postgres back-end
DATABASE_NAME = "cogdb"
DATABASE_USER = "dbsuper" #siteManager.get('DATABASE_USER')
DATABASE_PASSWORD = "<PASSWORD>" #siteManager.get('DATABASE_PASSWORD')
DATABASE_HOST = "pcmdi8vm.llnl.gov" #siteManager.get('DATABASE_HOST', default='localhost')
DATABASE_PORT = "5432" #siteManager.get('DATABASE_PORT', default=5432)
MY_PROJECTS_REFRESH_SECONDS = 3600
PWD_EXPIRATION_DAYS = 0 # 0: no expiration
IDP_REDIRECT = None #siteManager.get('IDP_REDIRECT', default=None)
VISUS_SITE = None
HOME_PROJECT = 'TestProject'
MEDIA_ROOT = ESGF_CONF_DIR + 'site_media'
DEFAULT_SEARCH_URL = "http://pcmdi8vm.llnl.gov/esg-search/search/"
DJANGO_DATABASE = "postgres"

DEBUG = True
ALLOWED_HOSTS = ['localhost'] #siteManager.get('ALLOWED_HOSTS', default=SITE_DOMAIN).split(",")
IDP_WHITELIST = ESGF_CONF_DIR + "esgf_idp.xml" #siteManager.get('IDP_WHITELIST', default=None)
KNOWN_PROVIDERS = ESGF_CONF_DIR + "esgf_known_providers.xml" #siteManager.get('KNOWN_PROVIDERS', default=None)
PEER_NODES = ESGF_CONF_DIR + "esgf_cogs.xml"#siteManager.get('PEER_NODES', default=None)
USE_CAPTCHA = False
# DEVELOPMENT/PRODUCTION server switch
PRODUCTION_SERVER = True

WPS_ENDPOINT = None
# Fields that will be added to the query string
WPS_FIELDS = []
WPS_DATACART = False

# FIXME
# ESGF specific settings

ESGF_HOSTNAME = "localhost"#siteManager.get('ESGF_HOSTNAME', section=SECTION_ESGF, default='')
ESGF_DBURL = "postgresql://dbsuper:EsgfLLNL@pc<EMAIL>.<EMAIL>.<EMAIL>/esgcet" #siteManager.get('ESGF_DBURL', section=SECTION_ESGF)
ESGF_VERSION = "2" #siteManager.get('ESGF_VERSION', section=SECTION_ESGF)
# FIXME

# PID specific settings
# PID_CONFIG = siteManager.isPidEnabled()
# if PID_CONFIG:
#     PID_PREFIX = siteManager.get('PID_PREFIX', section=SECTION_PID, default='21.14101')
#     PID_MESSAGING_SERVICE_EXCHANGE = siteManager.get('PID_EXCHANGE', section=SECTION_PID, default='esgffed-exchange')
#     PID_CREDENTIALS = siteManager.get('PID_CREDENTIALS', section=SECTION_PID, default=None).split('\n')

#====================== standard django settings.py ======================


# IMPORTANT: this setting must be set to True if using COG behind a proxy server,
# otherwise redirects won't work properly
USE_X_FORWARDED_HOST = True

ADMINS = (
    # ('<NAME>', '<EMAIL>'),
)

MANAGERS = ADMINS

DATABASES = {
    # SQLite database
    'sqllite3': {
        'ENGINE': 'django.db.backends.sqlite3',  # Add 'postgresql_psycopg2','postgresql','mysql','sqlite3' or 'oracle'.
        'NAME':   DATABASE_PATH,
        '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.
    },
    # Postgres
    'postgres': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': DATABASE_NAME,
        'USER': DATABASE_USER,                      # Not used with sqlite3.
        'PASSWORD': DATABASE_PASSWORD,              # Not used with sqlite3.
        'HOST': DATABASE_HOST,                      # Defaults to 'localhost'
        'PORT': DATABASE_PORT,                      # Set to empty string for default. Not used with sqlite3.
    }

}

DATABASES['default'] = DATABASES[DJANGO_DATABASE]

logging.info('>>> Using Django database=%s' % DJANGO_DATABASE)
if DJANGO_DATABASE == 'sqllite3':
    logging.info("Database path=%s" % DATABASE_PATH)

# 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 = 'America/Denver'
# use the system time zone, wherever the application is installed
#TIME_ZONE = None

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

# current site identifier - always first site in database
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

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
#MEDIA_ROOT = rel('site_media/')

# 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 = 'http://localhost:8000/site_media/'
MEDIA_URL = '/site_media/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a trailing slash.
# Examples: "http://foo.com/media/", "/media/".
STATIC_URL = '/static/'
STATIC_ROOT = rel('static/')


# absolute path to root directory containing projects data
DATA_ROOT = os.path.join(MEDIA_ROOT, "data/")

# custom template, media and configuration directories
MYTEMPLATES = ESGF_CONF_DIR + "mytemplates"
MYMEDIA = ESGF_CONF_DIR + "mymedia"

# project-specific configuration directories
# must be writable by web server
PROJECT_CONFIG_DIR = os.path.join(MEDIA_ROOT, 'config')


# Make this unique, and don't share it with anybody.
#SECRET_KEY = '<KEY>'

# new TEMPLATES settings
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
                 MYTEMPLATES,
                 rel('templates/'),
                 rel('static/'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.request',
                'cog.context_processors.cog_settings',
            ],
            'debug': DEBUG,
        },
    },
]

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'cog.middleware.init_middleware.InitMiddleware',
    'cog.middleware.login_middleware.LoginMiddleware',
    'cog.middleware.session_middleware.SessionMiddleware',
    #'cog.middleware.password_middleware.PasswordMiddleware'
    #'django.contrib.sites.middleware.CurrentSiteMiddleware' # django 1.7
    #'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)

#ROOT_URLCONF = 'COG.urls'
ROOT_URLCONF = 'urls'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django_openid_auth',
    'grappelli',
    'filebrowser',
    'django.contrib.admin.apps.SimpleAdminConfig',
    'django_comments',
    'django.contrib.staticfiles',
    'captcha',
    'layouts',
    'cog.apps.CogConfig',
    'cog.templatetags',
)

MIGRATION_MODULES = { 'django_openid_auth': 'cog.db_migrations.django_openid_auth' }

AUTHENTICATION_BACKENDS = (
    'django_openid_auth.auth.OpenIDBackend',
    'django.contrib.auth.backends.ModelBackend',
)

# Default is X_FRAME_OPTIONS='SAMEORIGIN'
# Using X_FRAME_OPTIONS = DENY breaks the CKEditor file uploader.
#X_FRAME_OPTIONS = 'DENY'

# login page URL (default: '/accounts/login')
LOGIN_URL = '/login/'

# OpenID login page
#LOGIN_URL = '/openid/login/'

# page to redirect after successful authentication, if 'next' parameter is not provided
#LOGIN_REDIRECT_URL='/cog/' # COG projects index
LOGIN_REDIRECT_URL = '/'  # welcome page

# Custom user profile
AUTH_PROFILE_MODULE = "cog.UserProfile"


# HTTPS support: can only send cookies via SSL connections
#if PRODUCTION_SERVER:
    #SESSION_COOKIE_SECURE = True
    #CSRF_COOKIE_SECURE = True
    #CSRF_COOKIE_HTTPONLY = True
    #SESSION_EXPIRE_AT_BROWSER_CLOSE = True

# CSS styles
#COLOR_DARK_TEAL = "#358C92"
#COLOR_LIGHT_TEAL = "#B9E0E3"

#COLOR_DARK_YELLOW = "#FAC2A4";
#COLOR_LIGHT_YELLOW = "#FCE79F";

#COLOR_DARK_GRAY = "#666666";

# FIXME: necessary for openid-auth since django 1.6.5 otherwise session is not serialized correctly
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

# default size limit of files uploaded by users
MAX_UPLOAD_SIZE = 52428800

#=== django filebrowser settings =========================

# Filebrowser directory relative to MEDIA_ROOT (IMPORTANT: must have trailing slash)
FILEBROWSER_DIRECTORY = "projects/"

# versions generated when browsing images
FILEBROWSER_VERSIONS = {
    'admin_thumbnail': {'verbose_name': 'Admin Thumbnail', 'width': 60, 'height': 60, 'opts': 'crop'},
    'thumbnail': {'verbose_name': 'Thumbnail', 'width': 60, 'height': 60, 'opts': 'crop'},
    #'small': {'verbose_name': 'Small (2 col)', 'width': 140, 'height': '', 'opts': ''},
    #'medium': {'verbose_name': 'Medium (4col )', 'width': 300, 'height': '', 'opts': ''},
    #'big': {'verbose_name': 'Big (6 col)', 'width': 460, 'height': '', 'opts': ''},
    #'large': {'verbose_name': 'Large (8 col)', 'width': 680, 'height': '', 'opts': ''},
}

# versions selectable through admin interface
FILEBROWSER_ADMIN_VERSIONS = ['thumbnail']

# absolute path to directory containing project specific media
PROJECTS_ROOT = os.path.join(MEDIA_ROOT, FILEBROWSER_DIRECTORY)

#=== django_openid_auth settings =========================

# create user account after first openid authentication
OPENID_CREATE_USERS = True

# do / do NOT keep updating the user profile from the IdP
OPENID_UPDATE_DETAILS_FROM_SREG = True

# list of allowed hosts to redirect to after successful openid login
# this is because django-openid-auth does not allow redirection to full URLs by default,
# unless the host is specifically enabled
ALLOWED_EXTERNAL_OPENID_REDIRECT_DOMAINS = [re.sub(':\d+','', SITE_DOMAIN) ]

#===== django-simpla-captcha =========

#CAPTCHA_LETTER_ROTATION = None
CAPTCHA_BACKGROUND_COLOR = '#FAC24A' # matches CoG dark yellow
#CAPTCHA_FOREGROUND_COLOR = "#666666" # matches CoG dark gray
CAPTCHA_IMAGE_SIZE = (100, 40)
#CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge'

#==== Quality Control Flags references ==================================

QCFLAGS_URLS = { 'obs4mips_indicators': 'https://www.earthsystemcog.org/projects/obs4mips/data-indicators' }

import os
import logging
import re
from cog.utils import str2bool

rel = lambda *x: os.path.join(os.path.abspath(os.path.dirname(__file__)), *x)

ESGF_CONF_DIR = os.getenv('ESGF_CONF_DIR', rel(''))

''' 
SITE SPECIFIC CONFIGURATION
These parameters are read from file 'cog_settings.cfg' 
located in directory COG_CONFIG_DIR (or by default '/usr/local/cog/cog_config').
Each parameter has a default value.
'''
CSRF_COOKIE_SECURE = False
SESSION_COOKIE_SECURE = False
from cog.constants import SECTION_ESGF, SECTION_PID
ESGF_CONFIG = True
SITE_NAME = "Local CoG" 
SITE_DOMAIN = "localhost:8000"
TIME_ZONE = 'America/Denver'
COG_MAILING_LIST = '<EMAIL>'
SECRET_KEY = '<KEY>
# for SQLLite back-end
DATABASE_PATH = ESGF_CONF_DIR + "django.data"
# for postgres back-end
DATABASE_NAME = "cogdb"
DATABASE_USER = "dbsuper" #siteManager.get('DATABASE_USER')
DATABASE_PASSWORD = "<PASSWORD>" #siteManager.get('DATABASE_PASSWORD')
DATABASE_HOST = "pcmdi8vm.llnl.gov" #siteManager.get('DATABASE_HOST', default='localhost')
DATABASE_PORT = "5432" #siteManager.get('DATABASE_PORT', default=5432)
MY_PROJECTS_REFRESH_SECONDS = 3600
PWD_EXPIRATION_DAYS = 0 # 0: no expiration
IDP_REDIRECT = None #siteManager.get('IDP_REDIRECT', default=None)
VISUS_SITE = None
HOME_PROJECT = 'TestProject'
MEDIA_ROOT = ESGF_CONF_DIR + 'site_media'
DEFAULT_SEARCH_URL = "http://pcmdi8vm.llnl.gov/esg-search/search/"
DJANGO_DATABASE = "postgres"

DEBUG = True
ALLOWED_HOSTS = ['localhost'] #siteManager.get('ALLOWED_HOSTS', default=SITE_DOMAIN).split(",")
IDP_WHITELIST = ESGF_CONF_DIR + "esgf_idp.xml" #siteManager.get('IDP_WHITELIST', default=None)
KNOWN_PROVIDERS = ESGF_CONF_DIR + "esgf_known_providers.xml" #siteManager.get('KNOWN_PROVIDERS', default=None)
PEER_NODES = ESGF_CONF_DIR + "esgf_cogs.xml"#siteManager.get('PEER_NODES', default=None)
USE_CAPTCHA = False
# DEVELOPMENT/PRODUCTION server switch
PRODUCTION_SERVER = True

WPS_ENDPOINT = None
# Fields that will be added to the query string
WPS_FIELDS = []
WPS_DATACART = False

# FIXME
# ESGF specific settings

ESGF_HOSTNAME = "localhost"#siteManager.get('ESGF_HOSTNAME', section=SECTION_ESGF, default='')
ESGF_DBURL = "postgresql://dbsuper:EsgfLLNL@pc<EMAIL>.<EMAIL>.<EMAIL>/esgcet" #siteManager.get('ESGF_DBURL', section=SECTION_ESGF)
ESGF_VERSION = "2" #siteManager.get('ESGF_VERSION', section=SECTION_ESGF)
# FIXME

# PID specific settings
# PID_CONFIG = siteManager.isPidEnabled()
# if PID_CONFIG:
#     PID_PREFIX = siteManager.get('PID_PREFIX', section=SECTION_PID, default='21.14101')
#     PID_MESSAGING_SERVICE_EXCHANGE = siteManager.get('PID_EXCHANGE', section=SECTION_PID, default='esgffed-exchange')
#     PID_CREDENTIALS = siteManager.get('PID_CREDENTIALS', section=SECTION_PID, default=None).split('\n')

#====================== standard django settings.py ======================


# IMPORTANT: this setting must be set to True if using COG behind a proxy server,
# otherwise redirects won't work properly
USE_X_FORWARDED_HOST = True

ADMINS = (
    # ('<NAME>', '<EMAIL>'),
)

MANAGERS = ADMINS

DATABASES = {
    # SQLite database
    'sqllite3': {
        'ENGINE': 'django.db.backends.sqlite3',  # Add 'postgresql_psycopg2','postgresql','mysql','sqlite3' or 'oracle'.
        'NAME':   DATABASE_PATH,
        '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.
    },
    # Postgres
    'postgres': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': DATABASE_NAME,
        'USER': DATABASE_USER,                      # Not used with sqlite3.
        'PASSWORD': DATABASE_PASSWORD,              # Not used with sqlite3.
        'HOST': DATABASE_HOST,                      # Defaults to 'localhost'
        'PORT': DATABASE_PORT,                      # Set to empty string for default. Not used with sqlite3.
    }

}

DATABASES['default'] = DATABASES[DJANGO_DATABASE]

logging.info('>>> Using Django database=%s' % DJANGO_DATABASE)
if DJANGO_DATABASE == 'sqllite3':
    logging.info("Database path=%s" % DATABASE_PATH)

# 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 = 'America/Denver'
# use the system time zone, wherever the application is installed
#TIME_ZONE = None

# Language code for this installation. All choices can be found here:
# http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = 'en-us'

# current site identifier - always first site in database
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

# Absolute path to the directory that holds media.
# Example: "/home/media/media.lawrence.com/"
#MEDIA_ROOT = rel('site_media/')

# 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 = 'http://localhost:8000/site_media/'
MEDIA_URL = '/site_media/'

# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a trailing slash.
# Examples: "http://foo.com/media/", "/media/".
STATIC_URL = '/static/'
STATIC_ROOT = rel('static/')


# absolute path to root directory containing projects data
DATA_ROOT = os.path.join(MEDIA_ROOT, "data/")

# custom template, media and configuration directories
MYTEMPLATES = ESGF_CONF_DIR + "mytemplates"
MYMEDIA = ESGF_CONF_DIR + "mymedia"

# project-specific configuration directories
# must be writable by web server
PROJECT_CONFIG_DIR = os.path.join(MEDIA_ROOT, 'config')


# Make this unique, and don't share it with anybody.
#SECRET_KEY = '<KEY>'

# new TEMPLATES settings
TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
                 MYTEMPLATES,
                 rel('templates/'),
                 rel('static/'),
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.contrib.auth.context_processors.auth',
                'django.template.context_processors.debug',
                'django.template.context_processors.i18n',
                'django.template.context_processors.media',
                'django.template.context_processors.static',
                'django.template.context_processors.tz',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.request',
                'cog.context_processors.cog_settings',
            ],
            'debug': DEBUG,
        },
    },
]

MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'cog.middleware.init_middleware.InitMiddleware',
    'cog.middleware.login_middleware.LoginMiddleware',
    'cog.middleware.session_middleware.SessionMiddleware',
    #'cog.middleware.password_middleware.PasswordMiddleware'
    #'django.contrib.sites.middleware.CurrentSiteMiddleware' # django 1.7
    #'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware',
)

#ROOT_URLCONF = 'COG.urls'
ROOT_URLCONF = 'urls'

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django_openid_auth',
    'grappelli',
    'filebrowser',
    'django.contrib.admin.apps.SimpleAdminConfig',
    'django_comments',
    'django.contrib.staticfiles',
    'captcha',
    'layouts',
    'cog.apps.CogConfig',
    'cog.templatetags',
)

MIGRATION_MODULES = { 'django_openid_auth': 'cog.db_migrations.django_openid_auth' }

AUTHENTICATION_BACKENDS = (
    'django_openid_auth.auth.OpenIDBackend',
    'django.contrib.auth.backends.ModelBackend',
)

# Default is X_FRAME_OPTIONS='SAMEORIGIN'
# Using X_FRAME_OPTIONS = DENY breaks the CKEditor file uploader.
#X_FRAME_OPTIONS = 'DENY'

# login page URL (default: '/accounts/login')
LOGIN_URL = '/login/'

# OpenID login page
#LOGIN_URL = '/openid/login/'

# page to redirect after successful authentication, if 'next' parameter is not provided
#LOGIN_REDIRECT_URL='/cog/' # COG projects index
LOGIN_REDIRECT_URL = '/'  # welcome page

# Custom user profile
AUTH_PROFILE_MODULE = "cog.UserProfile"


# HTTPS support: can only send cookies via SSL connections
#if PRODUCTION_SERVER:
    #SESSION_COOKIE_SECURE = True
    #CSRF_COOKIE_SECURE = True
    #CSRF_COOKIE_HTTPONLY = True
    #SESSION_EXPIRE_AT_BROWSER_CLOSE = True

# CSS styles
#COLOR_DARK_TEAL = "#358C92"
#COLOR_LIGHT_TEAL = "#B9E0E3"

#COLOR_DARK_YELLOW = "#FAC2A4";
#COLOR_LIGHT_YELLOW = "#FCE79F";

#COLOR_DARK_GRAY = "#666666";

# FIXME: necessary for openid-auth since django 1.6.5 otherwise session is not serialized correctly
SESSION_SERIALIZER = 'django.contrib.sessions.serializers.PickleSerializer'

# default size limit of files uploaded by users
MAX_UPLOAD_SIZE = 52428800

#=== django filebrowser settings =========================

# Filebrowser directory relative to MEDIA_ROOT (IMPORTANT: must have trailing slash)
FILEBROWSER_DIRECTORY = "projects/"

# versions generated when browsing images
FILEBROWSER_VERSIONS = {
    'admin_thumbnail': {'verbose_name': 'Admin Thumbnail', 'width': 60, 'height': 60, 'opts': 'crop'},
    'thumbnail': {'verbose_name': 'Thumbnail', 'width': 60, 'height': 60, 'opts': 'crop'},
    #'small': {'verbose_name': 'Small (2 col)', 'width': 140, 'height': '', 'opts': ''},
    #'medium': {'verbose_name': 'Medium (4col )', 'width': 300, 'height': '', 'opts': ''},
    #'big': {'verbose_name': 'Big (6 col)', 'width': 460, 'height': '', 'opts': ''},
    #'large': {'verbose_name': 'Large (8 col)', 'width': 680, 'height': '', 'opts': ''},
}

# versions selectable through admin interface
FILEBROWSER_ADMIN_VERSIONS = ['thumbnail']

# absolute path to directory containing project specific media
PROJECTS_ROOT = os.path.join(MEDIA_ROOT, FILEBROWSER_DIRECTORY)

#=== django_openid_auth settings =========================

# create user account after first openid authentication
OPENID_CREATE_USERS = True

# do / do NOT keep updating the user profile from the IdP
OPENID_UPDATE_DETAILS_FROM_SREG = True

# list of allowed hosts to redirect to after successful openid login
# this is because django-openid-auth does not allow redirection to full URLs by default,
# unless the host is specifically enabled
ALLOWED_EXTERNAL_OPENID_REDIRECT_DOMAINS = [re.sub(':\d+','', SITE_DOMAIN) ]

#===== django-simpla-captcha =========

#CAPTCHA_LETTER_ROTATION = None
CAPTCHA_BACKGROUND_COLOR = '#FAC24A' # matches CoG dark yellow
#CAPTCHA_FOREGROUND_COLOR = "#666666" # matches CoG dark gray
CAPTCHA_IMAGE_SIZE = (100, 40)
#CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge'

#==== Quality Control Flags references ==================================

QCFLAGS_URLS = { 'obs4mips_indicators': 'https://www.earthsystemcog.org/projects/obs4mips/data-indicators' }

SITE SPECIFIC CONFIGURATION These parameters are read from file 'cog_settings.cfg'  located in directory COG_CONFIG_DIR (or by default '/usr/local/cog/cog_config'). Each parameter has a default value. # for SQLLite back-end # for postgres back-end #siteManager.get('DATABASE_USER') #siteManager.get('DATABASE_PASSWORD') #siteManager.get('DATABASE_HOST', default='localhost') #siteManager.get('DATABASE_PORT', default=5432) # 0: no expiration #siteManager.get('IDP_REDIRECT', default=None) #siteManager.get('ALLOWED_HOSTS', default=SITE_DOMAIN).split(",") #siteManager.get('IDP_WHITELIST', default=None) #siteManager.get('KNOWN_PROVIDERS', default=None) # DEVELOPMENT/PRODUCTION server switch # Fields that will be added to the query string # FIXME # ESGF specific settings #siteManager.get('ESGF_DBURL', section=SECTION_ESGF) #siteManager.get('ESGF_VERSION', section=SECTION_ESGF) # FIXME # PID specific settings # PID_CONFIG = siteManager.isPidEnabled() # if PID_CONFIG: #     PID_PREFIX = siteManager.get('PID_PREFIX', section=SECTION_PID, default='21.14101') #     PID_MESSAGING_SERVICE_EXCHANGE = siteManager.get('PID_EXCHANGE', section=SECTION_PID, default='esgffed-exchange') #     PID_CREDENTIALS = siteManager.get('PID_CREDENTIALS', section=SECTION_PID, default=None).split('\n') #====================== standard django settings.py ====================== # IMPORTANT: this setting must be set to True if using COG behind a proxy server, # otherwise redirects won't work properly # ('<NAME>', '<EMAIL>'), # SQLite database # Add 'postgresql_psycopg2','postgresql','mysql','sqlite3' or 'oracle'. # Not used with sqlite3. # Not used with sqlite3. # Set to empty string for localhost. Not used with sqlite3. # Set to empty string for default. Not used with sqlite3. # Postgres # Not used with sqlite3. # Not used with sqlite3. # Defaults to 'localhost' # 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 # 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 = 'America/Denver' # use the system time zone, wherever the application is installed #TIME_ZONE = None # Language code for this installation. All choices can be found here: # http://www.i18nguy.com/unicode/language-identifiers.html # current site identifier - always first site in database # If you set this to False, Django will make some optimizations so as not # to load the internationalization machinery. # If you set this to False, Django will not format dates, numbers and # calendars according to the current locale # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" #MEDIA_ROOT = rel('site_media/') # 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 = 'http://localhost:8000/site_media/' # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a trailing slash. # Examples: "http://foo.com/media/", "/media/". # absolute path to root directory containing projects data # custom template, media and configuration directories # project-specific configuration directories # must be writable by web server # Make this unique, and don't share it with anybody. #SECRET_KEY = '<KEY>' # new TEMPLATES settings #'cog.middleware.password_middleware.PasswordMiddleware' #'django.contrib.sites.middleware.CurrentSiteMiddleware' # django 1.7 #'django.contrib.flatpages.middleware.FlatpageFallbackMiddleware', #ROOT_URLCONF = 'COG.urls' # Default is X_FRAME_OPTIONS='SAMEORIGIN' # Using X_FRAME_OPTIONS = DENY breaks the CKEditor file uploader. #X_FRAME_OPTIONS = 'DENY' # login page URL (default: '/accounts/login') # OpenID login page #LOGIN_URL = '/openid/login/' # page to redirect after successful authentication, if 'next' parameter is not provided #LOGIN_REDIRECT_URL='/cog/' # COG projects index # welcome page # Custom user profile # HTTPS support: can only send cookies via SSL connections #if PRODUCTION_SERVER: #SESSION_COOKIE_SECURE = True #CSRF_COOKIE_SECURE = True #CSRF_COOKIE_HTTPONLY = True #SESSION_EXPIRE_AT_BROWSER_CLOSE = True # CSS styles #COLOR_DARK_TEAL = "#358C92" #COLOR_LIGHT_TEAL = "#B9E0E3" #COLOR_DARK_YELLOW = "#FAC2A4"; #COLOR_LIGHT_YELLOW = "#FCE79F"; #COLOR_DARK_GRAY = "#666666"; # FIXME: necessary for openid-auth since django 1.6.5 otherwise session is not serialized correctly # default size limit of files uploaded by users #=== django filebrowser settings ========================= # Filebrowser directory relative to MEDIA_ROOT (IMPORTANT: must have trailing slash) # versions generated when browsing images #'small': {'verbose_name': 'Small (2 col)', 'width': 140, 'height': '', 'opts': ''}, #'medium': {'verbose_name': 'Medium (4col )', 'width': 300, 'height': '', 'opts': ''}, #'big': {'verbose_name': 'Big (6 col)', 'width': 460, 'height': '', 'opts': ''}, #'large': {'verbose_name': 'Large (8 col)', 'width': 680, 'height': '', 'opts': ''}, # versions selectable through admin interface # absolute path to directory containing project specific media #=== django_openid_auth settings ========================= # create user account after first openid authentication # do / do NOT keep updating the user profile from the IdP # list of allowed hosts to redirect to after successful openid login # this is because django-openid-auth does not allow redirection to full URLs by default, # unless the host is specifically enabled #===== django-simpla-captcha ========= #CAPTCHA_LETTER_ROTATION = None # matches CoG dark yellow #CAPTCHA_FOREGROUND_COLOR = "#666666" # matches CoG dark gray #CAPTCHA_CHALLENGE_FUNCT = 'captcha.helpers.math_challenge' #==== Quality Control Flags references ==================================