2016-08-15 18:10:02 +02:00
|
|
|
# c3nav settings, mostly taken from the pretix project
|
|
|
|
import configparser
|
2016-07-07 17:25:33 +02:00
|
|
|
import os
|
|
|
|
import string
|
2016-08-15 18:10:02 +02:00
|
|
|
import sys
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
from django.contrib.messages import constants as messages
|
2016-07-07 17:25:33 +02:00
|
|
|
from django.utils.crypto import get_random_string
|
2016-08-15 18:10:02 +02:00
|
|
|
from django.utils.translation import ugettext_lazy as _
|
|
|
|
|
|
|
|
config = configparser.RawConfigParser()
|
|
|
|
config.read(['/etc/c3nav/c3nav.cfg', os.path.expanduser('~/.c3nav.cfg'), 'c3nav.cfg'],
|
|
|
|
encoding='utf-8')
|
2016-07-07 17:25:33 +02:00
|
|
|
|
|
|
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
|
|
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
2016-08-15 18:10:02 +02:00
|
|
|
DATA_DIR = config.get('c3nav', 'datadir', fallback=os.environ.get('DATA_DIR', 'data'))
|
|
|
|
LOG_DIR = os.path.join(DATA_DIR, 'logs')
|
2016-08-23 02:19:02 +02:00
|
|
|
MEDIA_ROOT = os.path.join(DATA_DIR, 'media')
|
2016-08-29 22:10:43 +02:00
|
|
|
MAP_ROOT = os.path.join(DATA_DIR, 'map')
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
if not os.path.exists(DATA_DIR):
|
|
|
|
os.mkdir(DATA_DIR)
|
|
|
|
if not os.path.exists(LOG_DIR):
|
|
|
|
os.mkdir(LOG_DIR)
|
2016-08-23 02:19:02 +02:00
|
|
|
if not os.path.exists(MEDIA_ROOT):
|
|
|
|
os.mkdir(MEDIA_ROOT)
|
2016-08-29 22:10:43 +02:00
|
|
|
if not os.path.exists(MAP_ROOT):
|
|
|
|
os.mkdir(MAP_ROOT)
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
if config.has_option('django', 'secret'):
|
|
|
|
SECRET_KEY = config.get('django', 'secret')
|
2016-07-07 17:25:33 +02:00
|
|
|
else:
|
2016-08-15 18:10:02 +02:00
|
|
|
SECRET_FILE = os.path.join(BASE_DIR, '.secret')
|
|
|
|
if os.path.exists(SECRET_FILE):
|
|
|
|
with open(SECRET_FILE, 'r') as f:
|
|
|
|
SECRET_KEY = f.read().strip()
|
|
|
|
else:
|
|
|
|
SECRET_KEY = get_random_string(50, string.printable)
|
|
|
|
with open(SECRET_FILE, 'w') as f:
|
2016-08-16 01:39:59 +02:00
|
|
|
os.chmod(SECRET_FILE, 0o600)
|
|
|
|
os.chown(SECRET_FILE, os.getuid(), os.getgid())
|
2016-08-15 18:10:02 +02:00
|
|
|
f.write(SECRET_KEY)
|
|
|
|
|
|
|
|
# Adjustable settings
|
|
|
|
|
|
|
|
debug_fallback = "runserver" in sys.argv
|
|
|
|
DEBUG = config.getboolean('django', 'debug', fallback=debug_fallback)
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-23 11:41:04 +02:00
|
|
|
db_backend = config.get('database', 'backend', fallback='sqlite3')
|
2016-08-15 18:10:02 +02:00
|
|
|
DATABASES = {
|
|
|
|
'default': {
|
2016-08-23 11:41:04 +02:00
|
|
|
'ENGINE': 'django.db.backends.' + db_backend,
|
2016-08-15 18:10:02 +02:00
|
|
|
'NAME': config.get('database', 'name', fallback=os.path.join(DATA_DIR, 'db.sqlite3')),
|
|
|
|
'USER': config.get('database', 'user', fallback=''),
|
|
|
|
'PASSWORD': config.get('database', 'password', fallback=''),
|
|
|
|
'HOST': config.get('database', 'host', fallback=''),
|
|
|
|
'PORT': config.get('database', 'port', fallback=''),
|
|
|
|
'CONN_MAX_AGE': 0 if db_backend == 'sqlite3' else 120
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
STATIC_URL = config.get('urls', 'static', fallback='/static/')
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-16 01:39:59 +02:00
|
|
|
ALLOWED_HOSTS = [n for n in config.get('django', 'hosts', fallback='').split(',') if n]
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
LANGUAGE_CODE = config.get('locale', 'default', fallback='en')
|
|
|
|
TIME_ZONE = config.get('locale', 'timezone', fallback='UTC')
|
|
|
|
|
|
|
|
MAIL_FROM = SERVER_EMAIL = DEFAULT_FROM_EMAIL = config.get('mail', 'from', fallback='c3nav@localhost')
|
|
|
|
EMAIL_HOST = config.get('mail', 'host', fallback='localhost')
|
|
|
|
EMAIL_PORT = config.getint('mail', 'port', fallback=25)
|
|
|
|
EMAIL_HOST_USER = config.get('mail', 'user', fallback='')
|
|
|
|
EMAIL_HOST_PASSWORD = config.get('mail', 'password', fallback='')
|
|
|
|
EMAIL_USE_TLS = config.getboolean('mail', 'tls', fallback=False)
|
|
|
|
EMAIL_USE_SSL = config.getboolean('mail', 'ssl', fallback=False)
|
|
|
|
EMAIL_SUBJECT_PREFIX = '[c3nav] '
|
|
|
|
|
|
|
|
ADMINS = [('Admin', n) for n in config.get('mail', 'admins', fallback='').split(",") if n]
|
|
|
|
|
|
|
|
CACHES = {
|
|
|
|
'default': {
|
|
|
|
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
|
|
|
'LOCATION': 'unique-snowflake',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SESSION_COOKIE_DOMAIN = config.get('c3nav', 'cookie_domain', fallback=None)
|
2016-08-16 01:39:59 +02:00
|
|
|
SESSION_COOKIE_SECURE = config.getboolean('c3nav', 'session_cookie_secure', fallback=False)
|
2016-08-15 18:10:02 +02:00
|
|
|
|
|
|
|
# Internal settings
|
|
|
|
STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static.dist')
|
|
|
|
|
|
|
|
SESSION_COOKIE_NAME = 'c3nav_session'
|
|
|
|
LANGUAGE_COOKIE_NAME = 'c3nav_language'
|
|
|
|
CSRF_COOKIE_NAME = 'c3nav_csrftoken'
|
|
|
|
SESSION_COOKIE_HTTPONLY = True
|
|
|
|
|
2016-07-07 17:25:33 +02:00
|
|
|
|
|
|
|
# Application definition
|
|
|
|
|
|
|
|
INSTALLED_APPS = [
|
|
|
|
'django.contrib.admin',
|
|
|
|
'django.contrib.auth',
|
|
|
|
'django.contrib.contenttypes',
|
|
|
|
'django.contrib.sessions',
|
|
|
|
'django.contrib.messages',
|
|
|
|
'django.contrib.staticfiles',
|
2016-08-15 18:10:02 +02:00
|
|
|
'compressor',
|
|
|
|
'bootstrap3',
|
2016-08-17 14:34:43 +02:00
|
|
|
'c3nav.control',
|
2016-08-18 21:23:15 +02:00
|
|
|
'c3nav.mapdata',
|
2016-07-07 17:25:33 +02:00
|
|
|
]
|
|
|
|
|
|
|
|
MIDDLEWARE_CLASSES = [
|
|
|
|
'django.middleware.security.SecurityMiddleware',
|
|
|
|
'django.contrib.sessions.middleware.SessionMiddleware',
|
|
|
|
'django.middleware.common.CommonMiddleware',
|
|
|
|
'django.middleware.csrf.CsrfViewMiddleware',
|
|
|
|
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
|
|
|
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
|
|
|
|
'django.contrib.messages.middleware.MessageMiddleware',
|
|
|
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
|
|
|
]
|
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
# Security settings
|
|
|
|
X_FRAME_OPTIONS = 'DENY'
|
|
|
|
|
|
|
|
# URL settings
|
2016-07-07 17:25:33 +02:00
|
|
|
ROOT_URLCONF = 'c3nav.urls'
|
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
WSGI_APPLICATION = 'c3nav.wsgi.application'
|
|
|
|
|
|
|
|
USE_I18N = True
|
|
|
|
USE_L10N = True
|
|
|
|
USE_TZ = True
|
|
|
|
|
|
|
|
LOCALE_PATHS = (
|
|
|
|
os.path.join(os.path.dirname(__file__), 'locale'),
|
|
|
|
)
|
|
|
|
|
|
|
|
LANGUAGES = [
|
|
|
|
('en', _('English')),
|
|
|
|
('de', _('German')),
|
|
|
|
]
|
|
|
|
|
|
|
|
template_loaders = (
|
|
|
|
'django.template.loaders.filesystem.Loader',
|
|
|
|
'django.template.loaders.app_directories.Loader',
|
|
|
|
)
|
|
|
|
if not DEBUG:
|
|
|
|
template_loaders = (
|
|
|
|
('django.template.loaders.cached.Loader', template_loaders),
|
|
|
|
)
|
|
|
|
|
2016-07-07 17:25:33 +02:00
|
|
|
TEMPLATES = [
|
|
|
|
{
|
|
|
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
|
|
|
'DIRS': [],
|
|
|
|
'OPTIONS': {
|
|
|
|
'context_processors': [
|
2016-08-15 18:10:02 +02:00
|
|
|
'django.contrib.auth.context_processors.auth',
|
2016-07-07 17:25:33 +02:00
|
|
|
'django.template.context_processors.debug',
|
2016-08-15 18:10:02 +02:00
|
|
|
'django.template.context_processors.i18n',
|
2016-07-07 17:25:33 +02:00
|
|
|
'django.template.context_processors.request',
|
|
|
|
'django.contrib.auth.context_processors.auth',
|
|
|
|
'django.contrib.messages.context_processors.messages',
|
|
|
|
],
|
2016-08-15 18:10:02 +02:00
|
|
|
'loaders': template_loaders
|
2016-07-07 17:25:33 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
STATICFILES_FINDERS = (
|
|
|
|
'django.contrib.staticfiles.finders.FileSystemFinder',
|
|
|
|
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
|
|
|
|
'compressor.finders.CompressorFinder',
|
|
|
|
)
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-17 14:34:43 +02:00
|
|
|
STATICFILES_DIRS = (
|
|
|
|
os.path.join(BASE_DIR, 'static'),
|
|
|
|
)
|
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
COMPRESS_ENABLED = COMPRESS_OFFLINE = not debug_fallback
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
COMPRESS_CSS_FILTERS = (
|
|
|
|
'compressor.filters.css_default.CssAbsoluteFilter',
|
|
|
|
'compressor.filters.cssmin.CSSCompressorFilter',
|
|
|
|
)
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
INTERNAL_IPS = ('127.0.0.1', '::1')
|
|
|
|
|
|
|
|
MESSAGE_TAGS = {
|
|
|
|
messages.INFO: 'alert-info',
|
|
|
|
messages.ERROR: 'alert-danger',
|
|
|
|
messages.WARNING: 'alert-warning',
|
|
|
|
messages.SUCCESS: 'alert-success',
|
2016-07-07 17:25:33 +02:00
|
|
|
}
|
2016-08-15 18:10:02 +02:00
|
|
|
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
loglevel = 'DEBUG' if DEBUG else 'INFO'
|
2016-07-07 17:25:33 +02:00
|
|
|
|
2016-08-15 18:10:02 +02:00
|
|
|
LOGGING = {
|
|
|
|
'version': 1,
|
|
|
|
'disable_existing_loggers': False,
|
|
|
|
'formatters': {
|
|
|
|
'default': {
|
|
|
|
'format': '%(levelname)s %(asctime)s %(name)s %(module)s %(message)s'
|
|
|
|
},
|
|
|
|
},
|
|
|
|
'handlers': {
|
|
|
|
'console': {
|
|
|
|
'level': loglevel,
|
|
|
|
'class': 'logging.StreamHandler',
|
|
|
|
'formatter': 'default'
|
|
|
|
},
|
|
|
|
'file': {
|
|
|
|
'level': loglevel,
|
|
|
|
'class': 'logging.FileHandler',
|
|
|
|
'filename': os.path.join(LOG_DIR, 'c3nav.log'),
|
|
|
|
'formatter': 'default'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'loggers': {
|
|
|
|
'': {
|
|
|
|
'handlers': ['file', 'console'],
|
|
|
|
'level': loglevel,
|
|
|
|
'propagate': True,
|
|
|
|
},
|
|
|
|
'django.request': {
|
|
|
|
'handlers': ['file', 'console'],
|
|
|
|
'level': loglevel,
|
|
|
|
'propagate': True,
|
|
|
|
},
|
|
|
|
'django.security': {
|
|
|
|
'handlers': ['file', 'console'],
|
|
|
|
'level': loglevel,
|
|
|
|
'propagate': True,
|
|
|
|
},
|
|
|
|
'django.db.backends': {
|
|
|
|
'handlers': ['file', 'console'],
|
|
|
|
'level': 'INFO', # Do not output all the queries
|
|
|
|
'propagate': True,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
2016-07-07 17:25:33 +02:00
|
|
|
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
]
|