Source code for beat.web.settings.settings

#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

###############################################################################
#                                                                             #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/           #
# Contact: beat.support@idiap.ch                                              #
#                                                                             #
# This file is part of the beat.web module of the BEAT platform.              #
#                                                                             #
# Commercial License Usage                                                    #
# Licensees holding valid commercial BEAT licenses may use this file in       #
# accordance with the terms contained in a written agreement between you      #
# and Idiap. For further information contact tto@idiap.ch                     #
#                                                                             #
# Alternatively, this file may be used under the terms of the GNU Affero      #
# Public License version 3 as published by the Free Software and appearing    #
# in the file LICENSE.AGPL included in the packaging of this file.            #
# The BEAT platform is distributed in the hope that it will be useful, but    #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  #
# or FITNESS FOR A PARTICULAR PURPOSE.                                        #
#                                                                             #
# You should have received a copy of the GNU Affero Public License along      #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/.           #
#                                                                             #
###############################################################################

# Django settings for beat.web project.

import os
import logging
import pkg_resources

############################################################################
#
# GENERAL SETTINGS
#
############################################################################

ADMINS = (("name", "email"),)

MANAGERS = ADMINS
# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
TIME_ZONE = "Europe/Zurich"
# See http://www.i18nguy.com/unicode/language-identifiers.html
LANGUAGE_CODE = "en-us"
USE_I18N = True
USE_L10N = True
SITE_ID = 1
# This must be changed for every new instance - don't re-use this key
SECRET_KEY = "7o9k04*uju)4(-e29g)q+_o+z(%w_&(t^bl=)m_osg$@$y4&98"  # nosec

# The URL prefix prepends all URLs. Example: '/platform'
# WARNING! **Don't terminate this string with a '/' (slash)**
URL_PREFIX = ""

# Debug settings, set to False for production sites
DEBUG = True

USE_HTTPS_GRAVATAR = False

ALLOWED_HOSTS = ["localhost", "127.0.0.1"]

LOGGING = {
    "version": 1,
    "disable_existing_loggers": False,
    "formatters": {
        "simple": {
            "format": "[%(asctime)s - %(name)s] %(levelname)s: %(message)s",
            "datefmt": "%d/%b/%Y %H:%M:%S",
        }
    },
    "handlers": {
        "discard": {"level": "DEBUG", "class": "logging.NullHandler"},
        "console": {
            "level": "INFO",
            "class": "logging.StreamHandler",
            "formatter": "simple",
        },
        "mail_admins": {
            "level": "ERROR",
            "class": "django.utils.log.AdminEmailHandler",
        },
    },
    "loggers": {
        "": {"handlers": ["discard"], "level": "INFO"},
        "beat.core": {"handlers": ["console"]},
        "beat.core.scripts.worker": {"handlers": ["discard"], "propagate": False},
        "beat.web": {"handlers": ["console", "mail_admins"]},
        "beat.web.scripts.scheduler": {
            "handlers": ["console", "mail_admins"],
            "propagate": False,
        },
        "beat.web.attestations.management.commands": {
            "handlers": ["console"],
            "propagate": False,  # don't e-mail those!
        },
        "beat.web.search.management.commands": {
            "handlers": ["console"],
            "propagate": False,  # don't e-mail those!
        },
        "beat.web.experiments.management.commands": {
            "handlers": ["console"],
            "propagate": False,  # don't e-mail those!
        },
        "beat.web.reports.management.commands": {
            "handlers": ["console"],
            "propagate": False,  # don't e-mail those!
        },
        "beat.web.backend.management.commands": {
            "handlers": ["console"],
            "propagate": False,  # don't e-mail those!
        },
        "beat.web.utils.management.commands": {
            "handlers": ["console"],
            "propagate": False,  # don't e-mail those!
        },
    },
}


##############################################################################
#
# Special code to remove Django 1.10 deprecation warnings caused by
# Django-JSONField while that is not resolved:
# https://bitbucket.org/schinckel/django-jsonfield/issues/46/django-190-complains-about-subfieldbase
# Current django-jsonfield available: 0.9.19 (28.04.2016)
#
##############################################################################


[docs]class SuppressDeprecated(logging.Filter):
[docs] def filter(self, record): WARNINGS_TO_SUPPRESS = ["RemovedInDjango110Warning"] # Return false to suppress message. return not any([warn in record.getMessage() for warn in WARNINGS_TO_SUPPRESS])
warn_logger = logging.getLogger("py.warnings") warn_logger.addFilter(SuppressDeprecated()) ############################################################################## # # DATABASE # ############################################################################## DATABASES = { "default": { "ENGINE": "django.db.backends.sqlite3", "NAME": "django.sql3", "OPTIONS": {"timeout": 10}, # seconds } } ############################################################################## # # STATIC FILES # ############################################################################## STATIC_URL = "/static/" STATICFILES_DIRS = ( # Bower sources pkg_resources.resource_filename("beat.web", "static"), ) STATIC_ROOT = "static" ############################################################################## # # PREFIX (for BEAT platform files) # ############################################################################## PREFIX = os.path.join(os.getcwd(), "prefix") ALGORITHMS_ROOT = os.path.join(PREFIX, "algorithms") PLOTTERS_ROOT = os.path.join(PREFIX, "plotters") LIBRARIES_ROOT = os.path.join(PREFIX, "libraries") DATABASES_ROOT = os.path.join(PREFIX, "databases") DATAFORMATS_ROOT = os.path.join(PREFIX, "dataformats") TOOLCHAINS_ROOT = os.path.join(PREFIX, "toolchains") EXPERIMENTS_ROOT = os.path.join(PREFIX, "experiments") CACHE_ROOT = os.path.join(PREFIX, "cache") ############################################################################## # # IF ACCESS TO THE DATASETS IS RESTRICTED TO A SPECIFIC USER # ############################################################################## DATASETS_UID = None DATASETS_ROOT_PATH = None ############################################################################## # # ACCOUNTS # ############################################################################## ACCOUNT_ACTIVATION_DAYS = 2 ACCOUNT_ACTIVATION_DAYS_FROM_SUPERVISOR = 7 ACCOUNT_EXPIRATION_DAYS = 365 ACCOUNT_BLOCKAGE_AFTER_FIRST_REJECTION_DAYS = 56 LOGIN_REDIRECT_URL = "/" LOGIN_URL = "/login/" SYSTEM_ACCOUNT = "system" PLOT_ACCOUNT = "plot" PREREGISTRATION_ONLY = False TERMS_OF_SERVICE_VERSION = 1 LEGAL_DISCLAIMER_VERSION = 1 ACCOUNTS_TO_EXCLUDE_FROM_SEARCH = ["AnonymousUser"] ACCOUNTS_TO_EXCLUDE_FROM_TEAMS = [SYSTEM_ACCOUNT, PLOT_ACCOUNT, "AnonymousUser"] ########################################################################### # # E-MAILS # ########################################################################### DEFAULT_FROM_EMAIL = "BEAT Development Platform <beat.support@idiap.ch>" SERVER_EMAIL = DEFAULT_FROM_EMAIL EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" EMAIL_SUBJECT_PREFIX = "[BEAT/Development] " EMAIL_HOST = "localhost" EMAIL_PORT = 1025 EMAIL_HOST_USER = "" # nosec EMAIL_HOST_PASSWORD = "" # nosec EMAIL_USE_TLS = False ############################################################################## # # SCHEDULER # ############################################################################## # The scheduling interval controls the number of seconds between # scheduling attempts SCHEDULING_INTERVAL = 5 # seconds # If set, a testing panel that can accomplish scheduling activities will appear # at the scheduler page allowing administrators to launch scheduling activities # manually. SCHEDULING_PANEL = True # The verbosity level used by the local scheduler when starting the 'scheduler.py' # and 'worker.py' scripts LOCAL_SCHEDULER_VERBOSITY = "--verbose" LOCAL_SCHEDULER_ADDRESS = "127.0.0.1" LOCAL_SCHEDULER_PORT = 50000 LOCAL_SCHEDULER_USE_DOCKER = True ############################################################################## # # DJANGO MACHINERY # ############################################################################## TEMPLATES = [ { "BACKEND": "django.template.backends.django.DjangoTemplates", "DIRS": [pkg_resources.resource_filename("beat.web", "templates")], "APP_DIRS": True, "OPTIONS": { "context_processors": [ "django.contrib.auth.context_processors.auth", "django.template.context_processors.request", "django.template.context_processors.csrf", "django.contrib.messages.context_processors.messages", "beat.web.navigation.context_processors.exported_settings", "beat.web.navigation.context_processors.beat_version", ], "debug": DEBUG, }, } ] MIDDLEWARE_CLASSES = ( "django.middleware.security.SecurityMiddleware", "django.middleware.common.CommonMiddleware", "django.contrib.sessions.middleware.SessionMiddleware", "django.middleware.csrf.CsrfViewMiddleware", "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", "beat.web.navigation.middleware.AgreementMiddleware", ) ROOT_URLCONF = "beat.web.urls" INSTALLED_APPS = ( "django.contrib.contenttypes", "django.contrib.auth", "django.contrib.sessions", "django.contrib.staticfiles", "django.contrib.admin", "django.contrib.messages", "django.contrib.humanize", "django.contrib.sites", # 'django.contrib.admindocs', "guardian", "rest_framework", "drf_yasg", "rest_framework.authtoken", "jsonfield", "actstream", "beat.web.ui.registration", "beat.web.accounts", "beat.web.algorithms", "beat.web.plotters", "beat.web.attestations", "beat.web.backend", "beat.web.common", "beat.web.databases", "beat.web.dataformats", "beat.web.experiments", "beat.web.libraries", "beat.web.navigation", "beat.web.search", "beat.web.statistics", "beat.web.toolchains", "beat.web.ui", "beat.web.utils", "beat.web.team", "beat.web.reports", ) # Secure re-estructured text markup parsing RESTRUCTUREDTEXT_FILTER_SETTINGS = {"file_insertion_enabled": 0, "raw_enabled": 0} # Where CodeMirror is installed and some other settings CODEMIRROR_PATH = "codemirror" # w.r.t to STATIC_URL CODEMIRROR_THEME = "default" CODEMIRROR_MODE = "javascript" ############################################################################## # # DJANGO CACHING: https://docs.djangoproject.com/en/1.7/topics/cache/ # ############################################################################## CACHES = {"default": {"BACKEND": "django.core.cache.backends.dummy.DummyCache"}} ############################################################################## # # DJANGO SESSIONS: https://docs.djangoproject.com/en/1.7/topics/http/sessions/ # ############################################################################## SESSION_ENGINE = "django.contrib.sessions.backends.cached_db" ############################################################################## # # DJANGO AUTHENTICATION BACKENDS: https://docs.djangoproject.com/en/1.7/topics/auth/customizing/ # DJANGO-GUARDIAN CONFIGURATION http://django-guardian.readthedocs.org/en/v1.2/configuration.html # ############################################################################## AUTHENTICATION_BACKENDS = ( "django.contrib.auth.backends.ModelBackend", # this is default "guardian.backends.ObjectPermissionBackend", ) ANONYMOUS_USER_ID = -1 AUTH_PROFILE_MODULE = "accounts.Profile" ############################################################################## # # REST FRAMEWORK PERMISSION CLASSES: http://www.django-rest-framework.org/api-guide/permissions/ # ############################################################################## REST_FRAMEWORK = { # Use Django's standard `django.contrib.auth` permissions, # or allow read-only access for unauthenticated users. "DEFAULT_PERMISSION_CLASSES": [ "rest_framework.permissions.IsAuthenticatedOrReadOnly" ], "DEFAULT_AUTHENTICATION_CLASSES": [ "rest_framework.authentication.SessionAuthentication", "rest_framework.authentication.BasicAuthentication", "rest_framework.authentication.TokenAuthentication", ], "DEFAULT_RENDERER_CLASSES": [ "rest_framework.renderers.JSONRenderer", "rest_framework.renderers.BrowsableAPIRenderer", ], "DEFAULT_PARSER_CLASSES": ["rest_framework.parsers.JSONParser"], # This setting is mandatory after DRF 3.10 # 'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema' } ############################################################################## # # Attestations # ############################################################################## # In days EXPIRATION_DELTA = 180 EXPIRATION_REMINDERS = [1, 7, 30] EXPIRATION_REMINDERS_REVALIDATION = [1, 7, 30, 50] ############################################################################## # # Django Activity Stream # ############################################################################## ACTSTREAM_SETTINGS = { "USE_JSONFIELD": True, "MANAGER": "beat.web.common.managers.BeatActionManager", } ABSOLUTE_URL_OVERRIDES = { "auth.user": lambda u: URL_PREFIX + "/events/%s/" % u.username } SERIALIZATION_MODULES = {"json": "beat.web.utils.activity_stream_serializer"} ############################################################################## # # Documentation # ############################################################################## DOCUMENTATION_LINK = "https://www.idiap.ch/software/beat/docs/beat/docs/stable/beat.web/doc/user"