settings.py 6.34 KB
Newer Older
1
# -*- mode: python; coding: utf-8 -*-
2 3 4 5 6
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
# se veut agnostique au réseau considéré, de manière à être installable en
# quelques clics.
#
# Copyright © 2017  Gabriel Détraz
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
7
# Copyright © 2017  Lara Kermarec
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
# Copyright © 2017  Augustin Lemesle
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

chirac's avatar
chirac committed
24 25 26 27 28 29 30 31 32 33 34 35
"""
Django settings for re2o project.

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

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

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

36 37
from __future__ import unicode_literals

chirac's avatar
chirac committed
38
import os
Gabriel Detraz's avatar
Gabriel Detraz committed
39
from .settings_local import *
Maël Kervella's avatar
Maël Kervella committed
40
from django.utils.translation import ugettext_lazy as _
chirac's avatar
chirac committed
41

Maël Kervella's avatar
Maël Kervella committed
42 43
# The root directory for the project
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
chirac's avatar
chirac committed
44 45
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

46 47
# Auth definition
PASSWORD_HASHERS = (
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
48 49 50 51
    "re2o.login.SSHAPasswordHasher",
    "re2o.login.MD5PasswordHasher",
    "re2o.login.CryptPasswordHasher",
    "django.contrib.auth.hashers.PBKDF2PasswordHasher",
52
)
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
53 54 55
AUTH_USER_MODEL = "users.User"  # The class to use for authentication
LOGIN_URL = "/login/"  # The URL for login page
LOGIN_REDIRECT_URL = "/"  # The URL for redirecting after login
56

chirac's avatar
chirac committed
57
# Application definition
Maël Kervella's avatar
Maël Kervella committed
58
DJANGO_CONTRIB_APPS = (
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
59 60 61 62 63 64 65
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django.contrib.humanize",
Maël Kervella's avatar
Maël Kervella committed
66
)
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
67
EXTERNAL_CONTRIB_APPS = ("bootstrap3", "rest_framework", "reversion")
Maël Kervella's avatar
Maël Kervella committed
68
LOCAL_APPS = (
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
69 70 71 72 73 74 75 76
    "users",
    "machines",
    "cotisations",
    "topologie",
    "search",
    "re2o",
    "preferences",
    "logs",
Maël Kervella's avatar
Maël Kervella committed
77 78
)
INSTALLED_APPS = (
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
79
    DJANGO_CONTRIB_APPS + EXTERNAL_CONTRIB_APPS + LOCAL_APPS + OPTIONNAL_APPS
Maël Kervella's avatar
Maël Kervella committed
80
)
chirac's avatar
chirac committed
81
MIDDLEWARE_CLASSES = (
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
82 83 84 85 86 87 88 89 90 91
    "django.contrib.sessions.middleware.SessionMiddleware",
    "django.middleware.locale.LocaleMiddleware",
    "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",
    "django.middleware.security.SecurityMiddleware",
    "reversion.middleware.RevisionMiddleware",
chirac's avatar
chirac committed
92
)
93

Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
94
AUTHENTICATION_BACKENDS = ["re2o.login.RecryptBackend"]
95

96
# Include debug_toolbar middleware if activated
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
97
if "debug_toolbar" in INSTALLED_APPS:
98 99
    # Include this middleware at the beggining
    MIDDLEWARE_CLASSES = (
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
100
        "debug_toolbar.middleware.DebugToolbarMiddleware",
101 102 103
    ) + MIDDLEWARE_CLASSES
    # Change the default show_toolbar middleware
    DEBUG_TOOLBAR_CONFIG = {
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
104
        "SHOW_TOOLBAR_CALLBACK": "re2o.middleware.show_debug_toolbar"
105
    }
chirac's avatar
chirac committed
106

Maël Kervella's avatar
Maël Kervella committed
107
# The root url module to define the project URLs
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
108
ROOT_URLCONF = "re2o.urls"
chirac's avatar
chirac committed
109

Maël Kervella's avatar
Maël Kervella committed
110
# The templates configuration (see Django documentation)
chirac's avatar
chirac committed
111 112
TEMPLATES = [
    {
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
113 114
        "BACKEND": "django.template.backends.django.DjangoTemplates",
        "DIRS": [
Maël Kervella's avatar
Maël Kervella committed
115
            # Use only absolute paths with '/' delimiters even on Windows
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
116 117
            os.path.join(BASE_DIR, "templates").replace("\\", "/"),
            os.path.join(BASE_DIR, "media", "templates").replace("\\", "/"),
Maël Kervella's avatar
Maël Kervella committed
118
        ],
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
119 120 121 122 123 124 125 126 127 128 129 130
        "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",
                "django.template.context_processors.request",
                "re2o.context_processors.context_user",
                "re2o.context_processors.context_optionnal_apps",
                "re2o.context_processors.date_now",
            ]
chirac's avatar
chirac committed
131
        },
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
132
    }
chirac's avatar
chirac committed
133 134
]

Maël Kervella's avatar
Maël Kervella committed
135
# The WSGI module to use in a server environment
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
136
WSGI_APPLICATION = "re2o.wsgi.application"
chirac's avatar
chirac committed
137 138 139

# Internationalization
# https://docs.djangoproject.com/en/1.8/topics/i18n/
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
140
LANGUAGE_CODE = "en"
Maël Kervella's avatar
Maël Kervella committed
141 142
USE_I18N = True
USE_L10N = True
143 144
# Proritary location search for translations
# then searches in {app}/locale/ for app in INSTALLED_APPS
Maël Kervella's avatar
Maël Kervella committed
145
# Use only absolute paths with '/' delimiters even on Windows
146
LOCALE_PATHS = [
Maël Kervella's avatar
Maël Kervella committed
147
    # For translations outside of apps
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
148
    os.path.join(BASE_DIR, "templates", "locale").replace("\\", "/")
Maël Kervella's avatar
Maël Kervella committed
149
]
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
150
LANGUAGES = [("en", _("English")), ("fr", _("French"))]
151

Maël Kervella's avatar
Maël Kervella committed
152
# Should use time zone ?
chirac's avatar
chirac committed
153 154
USE_TZ = True

Maël Kervella's avatar
Maël Kervella committed
155
# Router config for database
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
156
DATABASE_ROUTERS = ["ldapdb.router.Router"]
157

Maël Kervella's avatar
Maël Kervella committed
158
# django-bootstrap3 config
chirac's avatar
chirac committed
159
BOOTSTRAP3 = {
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
160 161 162
    "jquery_url": "/javascript/jquery/jquery.min.js",
    "base_url": "/javascript/bootstrap/",
    "include_jquery": True,
Maël Kervella's avatar
Maël Kervella committed
163
}
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
164
BOOTSTRAP_BASE_URL = "/javascript/bootstrap/"
chirac's avatar
chirac committed
165

Maël Kervella's avatar
Maël Kervella committed
166 167
# Directories where collectstatic should look for static files
# Use only absolute paths with '/' delimiters even on Windows
chirac's avatar
chirac committed
168
STATICFILES_DIRS = (
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
169
    os.path.join(BASE_DIR, "static").replace("\\", "/"),
erdnaxe's avatar
erdnaxe committed
170
    "/usr/share/fonts-font-awesome/",
chirac's avatar
chirac committed
171
)
172
# Directory where the static files served by the server are stored
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
173
STATIC_ROOT = os.path.join(BASE_DIR, "static_files")
Maël Kervella's avatar
Maël Kervella committed
174
# The URL to access the static files
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
175
STATIC_URL = "/static/"
176
# Directory where the media files served by the server are stored
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
177
MEDIA_ROOT = os.path.join(BASE_DIR, "media").replace("\\", "/")
178
# The URL to access the static files
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
179
MEDIA_URL = os.path.join(BASE_DIR, "/media/")
180

Maël Kervella's avatar
Maël Kervella committed
181
# Models to use for graphs
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
182
GRAPH_MODELS = {"all_applications": True, "group_models": True}
Maël Kervella's avatar
Maël Kervella committed
183

184
# Activate API
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
185
if "api" in INSTALLED_APPS:
186
    from api.settings import *
Hugo Levy-Falk's avatar
Hugo Levy-Falk committed
187

188
    INSTALLED_APPS += API_APPS