settings.py 4.93 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
"""
Florent Chehab's avatar
Florent Chehab committed
2
Django settings
Florent Chehab's avatar
Florent Chehab committed
3
4
5
6
7
8
9
10
11

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
Florent Chehab's avatar
Florent Chehab committed
12
from os.path import dirname
13
import sys
Florent Chehab's avatar
Florent Chehab committed
14

Florent Chehab's avatar
Florent Chehab committed
15
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Florent Chehab's avatar
Florent Chehab committed
16
BASE_DIR = dirname(dirname(dirname(os.path.abspath(__file__))))
Florent Chehab's avatar
Florent Chehab committed
17

Florent Chehab's avatar
Florent Chehab committed
18
SECRET_KEY = os.environ["SECRET_KEY"]
19
20

# Application definition
Florent Chehab's avatar
Florent Chehab committed
21
INSTALLED_APPS = [
22
23
24
25
26
27
28
29
30
31
32
33
34
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django_cas_ng",
    "reversion",
    "reversion_compare",
    "rest_framework",
    "rest_framework.authtoken",
    "backend_app",
    "frontend_app",
35
    "webpack_loader",
Florent Chehab's avatar
Florent Chehab committed
36
37
38
]

MIDDLEWARE = [
39
40
41
42
43
44
45
46
    "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",
    "base_app.middleware.LoginRequiredMiddleware",
Florent Chehab's avatar
Florent Chehab committed
47
]
Florent Chehab's avatar
Florent Chehab committed
48
MODERATION_ACTIVATED = True
Florent Chehab's avatar
Florent Chehab committed
49

Florent Chehab's avatar
Florent Chehab committed
50
51
52
53
54
if os.environ["ENV"] == "DEV":
    DEBUG = True
    ALLOWED_HOSTS = ["*"]
    INSTALLED_APPS += ["django_extensions", "debug_toolbar"]
    MIDDLEWARE = ["debug_toolbar.middleware.DebugToolbarMiddleware"] + MIDDLEWARE
Florent Chehab's avatar
Florent Chehab committed
55

56

Florent Chehab's avatar
Florent Chehab committed
57
58
59
60
61
62
63
64
65
66
67
68
69
70
else:
    DEBUG = False

##########
# Webpack loader related
WEBPACK_LOADER = {
    "DEFAULT": {
        "BUNDLE_DIR_NAME": "frontend_app/bundles/",
        "STATS_FILE": os.path.join(BASE_DIR, "frontend/webpack-stats.json"),
    }
}

STATICFILES_DIRS = (
    os.path.join(
71
        BASE_DIR, "backend/static/frontend_app/bundles/"
Florent Chehab's avatar
Florent Chehab committed
72
73
74
75
76
77
78
    ),  # We do this so that django's collectstatic copies or our bundles to the STATIC_ROOT or syncs them to whatever storage we use.
)
# End of webpack loader related
###########


ALLOWED_PHOTOS_EXTENSION = ["jpg", "jpeg", "png", "svg"]
79
INTERNAL_IPS = ["127.0.0.1"]
Florent Chehab's avatar
Florent Chehab committed
80

81
LOGIN_URL = "/user/login"
Florent Chehab's avatar
Florent Chehab committed
82
LOGIN_EXEMPT_URLS = [LOGIN_URL, "/admin/"]
Florent Chehab's avatar
Florent Chehab committed
83
84

AUTHENTICATION_BACKENDS = [
85
86
    "django.contrib.auth.backends.ModelBackend",
    "django_cas_ng.backends.CASBackend",
Florent Chehab's avatar
linting  
Florent Chehab committed
87
]
Florent Chehab's avatar
Florent Chehab committed
88

89
CAS_SERVER_URL = "https://cas.utc.fr/cas/"
Florent Chehab's avatar
Florent Chehab committed
90
CAS_APPLY_ATTRIBUTES_TO_USER = True
91
CAS_RENAME_ATTRIBUTES = {"mail": "email", "givenName": "first_name", "sn": "last_name"}
Florent Chehab's avatar
Florent Chehab committed
92

Florent Chehab's avatar
Florent Chehab committed
93
94
95
96
97
TESTING = "pytest" in sys.modules
if TESTING:
    LOGIN_EXEMPT_URLS.append("api")


Florent Chehab's avatar
Florent Chehab committed
98
99
REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
100
101
102
103
104
105
    "DEFAULT_PERMISSION_CLASSES": (
        "rest_framework.permissions.DjangoModelPermissions",
    ),
    "DEFAULT_AUTHENTICATION_CLASSES": (
        "rest_framework.authentication.SessionAuthentication",
        "rest_framework.authentication.TokenAuthentication",
Florent Chehab's avatar
Florent Chehab committed
106
107
108
    ),
}

Florent Chehab's avatar
Florent Chehab committed
109
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
Florent Chehab's avatar
Florent Chehab committed
110

111
ROOT_URLCONF = "base_app.urls"
Florent Chehab's avatar
Florent Chehab committed
112
113
114

TEMPLATES = [
    {
115
116
117
118
119
120
121
122
123
124
        "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",
            ]
Florent Chehab's avatar
Florent Chehab committed
125
        },
126
    }
Florent Chehab's avatar
Florent Chehab committed
127
128
]

129
WSGI_APPLICATION = "base_app.wsgi.application"
Florent Chehab's avatar
Florent Chehab committed
130
131
132
133
134


# Database
# https://docs.djangoproject.com/en/2.0/ref/settings/#databases

Florent Chehab's avatar
Florent Chehab committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.postgresql_psycopg2",
        "NAME": os.environ["POSTGRES_DB"],
        "USER": os.environ["POSTGRES_USER"],
        "PASSWORD": os.environ["POSTGRES_PASSWORD"],
        "HOST": os.environ["DB_HOST"],
        "PORT": os.environ["DB_PORT"],
    }
}

# To use Sqlite, uncomment below
# PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
# DATABASES = {
#     "default": {
#         "ENGINE": "django.db.backends.sqlite3",
#         "NAME": os.path.join(PROJECT_DIR, "../database.db"),
#     }
# }
Florent Chehab's avatar
Florent Chehab committed
154
155
156
157
158
159
160


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

AUTH_PASSWORD_VALIDATORS = [
    {
161
162
        "NAME": "django.contrib.auth.password_validation."
        "UserAttributeSimilarityValidator"
Florent Chehab's avatar
Florent Chehab committed
163
    },
164
165
166
    {"NAME": "django.contrib.auth.password_validation." "MinimumLengthValidator"},
    {"NAME": "django.contrib.auth.password_validation." "CommonPasswordValidator"},
    {"NAME": "django.contrib.auth.password_validation." "NumericPasswordValidator"},
Florent Chehab's avatar
Florent Chehab committed
167
168
169
170
171
172
]


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

173
174
LANGUAGE_CODE = "fr-fr"
TIME_ZONE = "Europe/Paris"
Florent Chehab's avatar
Florent Chehab committed
175
176
177
178
USE_I18N = True
USE_L10N = True
USE_TZ = True

Florent Chehab's avatar
Florent Chehab committed
179
180
181
STATIC_URL = "/static/"
STATIC_ROOT = os.path.join(BASE_DIR, "static")

182
183
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"