<reponame>vanandrew/web-common
"""
Django settings for labsite project.

Generated by 'django-admin startproject' using Django 2.0.3.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os
import dropbox
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<KEY>'

# SECURITY WARNING: don't run with debug turned on in production!
try:
    DEBUG = (os.environ['DEBUG'] == "TRUE") # Get DEBUG variable
except:
    DEBUG = False
if DEBUG: # Do these things if in DEBUG mode
    pass
else: # Do these things when DEBUG is disabled
    SECURE_CONTENT_TYPE_NOSNIFF = True
    SECURE_SSL_REDIRECT = True

ALLOWED_HOSTS = ['grattonlabbackend.herokuapp.com','www.grattonlab.org','localhost']

# Application definition

INSTALLED_APPS = [
    'common.apps.CommonConfig',
    'suit',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'ckeditor',
    'ckeditor_uploader'
]

MIDDLEWARE = [
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.middleware.security.SecurityMiddleware',
    '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 = 'labsite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'labsite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'test.db'
    }
}
# Use the DATABASE_URL env variable
try:
    if os.environ['PRODUCTION'] == "TRUE":
        DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)
        print('DATABASE has been set to heroku postgres.')
except KeyError:
    pass

# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Chicago'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

# Set Dropbox OAUTH TOKEN and file storage only if defined
try:
    # set the token
    DROPBOX_OAUTH2_TOKEN = os.environ['DROPBOX_TOKEN']
    # Set default file storage
    DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage'
    # Set Dropbox Path
    DROPBOX_ROOT_PATH = 'caterina-website'
    STATIC_MEDIA = False
except KeyError:
    print('Dropbox token not defined!')
    MEDIA_URL = '/media/'
    MEDIA_ROOT = os.path.join(BASE_DIR,'media')
    STATIC_MEDIA = True

# Set ckeditor settings
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_IMAGE_BACKEND = "pillow"
CKEDITOR_CONFIGS = {
    'default': {
        'width': '100%'
    }
}

# Django suit config
SUIT_CONFIG = {
    #header
    'ADMIN_NAME': '<NAME>',
    'HEADER_DATE_FORMAT': 'l, j. F Y',
    'HEADER_TIME_FORMAT': 'h:i A',
    #forms
    'SHOW_REQUIRED_ASTERISK': True,  # Default True
    'CONFIRM_UNSAVED_CHANGES': True, # Default True
    #menu
    'SEARCH_URL': '',
    'MENU_ICONS': {
       'sites': 'icon-leaf',
       'common': 'icon-th',
       'auth': 'icon-lock',
    },
    'MENU_OPEN_FIRST_CHILD': True, # Default True
    'MENU_EXCLUDE': ('auth.group',),
    'MENU': (
        'sites',
        'common',
        'auth',
        {'label': 'Go to site','url': '/'}
    ),
    #misc
    'LIST_PER_PAGE': 15
}

# Set static directory
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')

"""
Django settings for labsite project.

Generated by 'django-admin startproject' using Django 2.0.3.

For more information on this file, see
https://docs.djangoproject.com/en/2.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/2.0/ref/settings/
"""

import os
import dropbox
import dj_database_url

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '<KEY>'

# SECURITY WARNING: don't run with debug turned on in production!
try:
    DEBUG = (os.environ['DEBUG'] == "TRUE") # Get DEBUG variable
except:
    DEBUG = False
if DEBUG: # Do these things if in DEBUG mode
    pass
else: # Do these things when DEBUG is disabled
    SECURE_CONTENT_TYPE_NOSNIFF = True
    SECURE_SSL_REDIRECT = True

ALLOWED_HOSTS = ['grattonlabbackend.herokuapp.com','www.grattonlab.org','localhost']

# Application definition

INSTALLED_APPS = [
    'common.apps.CommonConfig',
    'suit',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'ckeditor',
    'ckeditor_uploader'
]

MIDDLEWARE = [
    'whitenoise.middleware.WhiteNoiseMiddleware',
    'django.middleware.security.SecurityMiddleware',
    '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 = 'labsite.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'labsite.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': 'test.db'
    }
}
# Use the DATABASE_URL env variable
try:
    if os.environ['PRODUCTION'] == "TRUE":
        DATABASES['default'] = dj_database_url.config(conn_max_age=600, ssl_require=True)
        print('DATABASE has been set to heroku postgres.')
except KeyError:
    pass

# Password validation
# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.0/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Chicago'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/

# Set Dropbox OAUTH TOKEN and file storage only if defined
try:
    # set the token
    DROPBOX_OAUTH2_TOKEN = os.environ['DROPBOX_TOKEN']
    # Set default file storage
    DEFAULT_FILE_STORAGE = 'storages.backends.dropbox.DropBoxStorage'
    # Set Dropbox Path
    DROPBOX_ROOT_PATH = 'caterina-website'
    STATIC_MEDIA = False
except KeyError:
    print('Dropbox token not defined!')
    MEDIA_URL = '/media/'
    MEDIA_ROOT = os.path.join(BASE_DIR,'media')
    STATIC_MEDIA = True

# Set ckeditor settings
CKEDITOR_UPLOAD_PATH = 'uploads/'
CKEDITOR_IMAGE_BACKEND = "pillow"
CKEDITOR_CONFIGS = {
    'default': {
        'width': '100%'
    }
}

# Django suit config
SUIT_CONFIG = {
    #header
    'ADMIN_NAME': '<NAME>',
    'HEADER_DATE_FORMAT': 'l, j. F Y',
    'HEADER_TIME_FORMAT': 'h:i A',
    #forms
    'SHOW_REQUIRED_ASTERISK': True,  # Default True
    'CONFIRM_UNSAVED_CHANGES': True, # Default True
    #menu
    'SEARCH_URL': '',
    'MENU_ICONS': {
       'sites': 'icon-leaf',
       'common': 'icon-th',
       'auth': 'icon-lock',
    },
    'MENU_OPEN_FIRST_CHILD': True, # Default True
    'MENU_EXCLUDE': ('auth.group',),
    'MENU': (
        'sites',
        'common',
        'auth',
        {'label': 'Go to site','url': '/'}
    ),
    #misc
    'LIST_PER_PAGE': 15
}

# Set static directory
STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR,'static')
Django settings for labsite project.  Generated by 'django-admin startproject' using Django 2.0.3.  For more information on this file, see https://docs.djangoproject.com/en/2.0/topics/settings/  For the full list of settings and their values, see https://docs.djangoproject.com/en/2.0/ref/settings/ # Build paths inside the project like this: os.path.join(BASE_DIR, ...) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! # SECURITY WARNING: don't run with debug turned on in production! # Get DEBUG variable # Do these things if in DEBUG mode # Do these things when DEBUG is disabled # Application definition # Database # https://docs.djangoproject.com/en/2.0/ref/settings/#databases # Use the DATABASE_URL env variable # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators # Internationalization # https://docs.djangoproject.com/en/2.0/topics/i18n/ # Static files (CSS, JavaScript, Images) # https://docs.djangoproject.com/en/2.0/howto/static-files/ # Set Dropbox OAUTH TOKEN and file storage only if defined # set the token # Set default file storage # Set Dropbox Path # Set ckeditor settings # Django suit config #header #forms # Default True # Default True #menu # Default True #misc # Set static directory