settings.py 5.27 KB
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
3
4
5
6
7
8
9
10
11
12
13
"""
Django settings for outgoing_rex 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
14
import sys
Florent Chehab's avatar
Florent Chehab committed
15
16
import django_heroku
import dj_database_url
Florent Chehab's avatar
Florent Chehab committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30

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

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django_cas_ng',
31
32
    'reversion',
    'reversion_compare',
Florent Chehab's avatar
Florent Chehab committed
33
34
    'rest_framework',
    'rest_framework.authtoken',
35
    'backend',
Florent Chehab's avatar
Florent Chehab committed
36
    'frontend',
37
    'django_extensions',
Florent Chehab's avatar
Florent Chehab committed
38
    'debug_toolbar',
Florent Chehab's avatar
Florent Chehab committed
39
40
41
]

MIDDLEWARE = [
Florent Chehab's avatar
Florent Chehab committed
42
    'debug_toolbar.middleware.DebugToolbarMiddleware',
Florent Chehab's avatar
Florent Chehab committed
43
44
45
46
47
48
49
    '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',
Florent Chehab's avatar
Florent Chehab committed
50
    'general.middleware.LoginRequiredMiddleware',
Florent Chehab's avatar
Florent Chehab committed
51
52
]

53
54
# If we want to activate the moderation functionnalities
MODERATION_ACTIVATED = True
55
TESTING = "pytest" in sys.modules
56
ALLOWED_PHOTOS_EXTENSION = ["jpg", "jpeg", "png", "svg"]
57

Florent Chehab's avatar
Florent Chehab committed
58
59
INTERNAL_IPS = ['127.0.0.1']

Florent Chehab's avatar
Florent Chehab committed
60
61
62
63
LOGIN_URL = '/user/login'
LOGIN_EXEMPT_URLS = [LOGIN_URL,
                     '/admin/',
                     'api']
Florent Chehab's avatar
Florent Chehab committed
64
65
66
67

AUTHENTICATION_BACKENDS = [
    'django.contrib.auth.backends.ModelBackend',
    'django_cas_ng.backends.CASBackend',
Florent Chehab's avatar
linting    
Florent Chehab committed
68
]
Florent Chehab's avatar
Florent Chehab committed
69

Florent Chehab's avatar
Florent Chehab committed
70
CAS_SERVER_URL = 'https://cas.utc.fr/cas/'
Florent Chehab's avatar
Florent Chehab committed
71
CAS_APPLY_ATTRIBUTES_TO_USER = True
Florent Chehab's avatar
Florent Chehab committed
72
73
74
75
CAS_RENAME_ATTRIBUTES = {
    'mail': 'email',
    'givenName': 'first_name',
    'sn': 'last_name'
Florent Chehab's avatar
Florent Chehab committed
76
77
}

Florent Chehab's avatar
Florent Chehab committed
78
79
80
81
82
83
84
85
86
87
88
REST_FRAMEWORK = {
    # Use Django's standard `django.contrib.auth` permissions,
    '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
89
SESSION_EXPIRE_AT_BROWSER_CLOSE = True
Florent Chehab's avatar
Florent Chehab committed
90

Florent Chehab's avatar
Florent Chehab committed
91
ROOT_URLCONF = 'general.urls'
Florent Chehab's avatar
Florent Chehab committed
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108

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',
            ],
        },
    },
]

Florent Chehab's avatar
Florent Chehab committed
109
WSGI_APPLICATION = 'general.wsgi.application'
Florent Chehab's avatar
Florent Chehab committed
110
111
112
113
114


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

Florent Chehab's avatar
Florent Chehab committed
115
# DB are set at the end of the file
Florent Chehab's avatar
Florent Chehab committed
116
DATABASES = {
Florent Chehab's avatar
Florent Chehab committed
117
    'default': None
Florent Chehab's avatar
Florent Chehab committed
118
119
120
121
122
123
124
125
}


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

AUTH_PASSWORD_VALIDATORS = [
    {
126
127
        'NAME': 'django.contrib.auth.password_validation.'
        'UserAttributeSimilarityValidator',
Florent Chehab's avatar
Florent Chehab committed
128
129
    },
    {
130
131
        'NAME': 'django.contrib.auth.password_validation.'
        'MinimumLengthValidator',
Florent Chehab's avatar
Florent Chehab committed
132
133
    },
    {
134
135
        'NAME': 'django.contrib.auth.password_validation.'
        'CommonPasswordValidator',
Florent Chehab's avatar
Florent Chehab committed
136
137
    },
    {
138
139
        'NAME': 'django.contrib.auth.password_validation.'
        'NumericPasswordValidator',
Florent Chehab's avatar
Florent Chehab committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
    },
]


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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Europe/Paris'

USE_I18N = True

USE_L10N = True

USE_TZ = True


Florent Chehab's avatar
Florent Chehab committed
158
# override DATABASE_URL set by django_heroku because it forces SSL mode locally
Florent Chehab's avatar
Florent Chehab committed
159
160
161
162
try:
    dev_env = os.environ['ENV'] == 'development'
except KeyError:
    dev_env = False
Florent Chehab's avatar
Florent Chehab committed
163
164

if dev_env:
165
    print("You are running in development mode")
Florent Chehab's avatar
Florent Chehab committed
166
167
168
169
    DEBUG = True
    ALLOWED_HOSTS = []
    SECRET_KEY = '0a1kbtt%as4624u*9+r+c%j1tlq&dc08==c3w604(4igc+t6tw'

Florent Chehab's avatar
Florent Chehab committed
170
171
172
173
174
    # DATABASE
    # After you have read the documentation, uncomment the
    # block with the database system you would like to use.

    # POSTGRESQL
Florent Chehab's avatar
Florent Chehab committed
175
176
177
178
    # If bellow fails, your need to add DATABASE_URL and ENV to your virutalenv
    locals()['DATABASES']['default'] = dj_database_url.config(
        conn_max_age=django_heroku.MAX_CONN_AGE, ssl_require=not dev_env)

Florent Chehab's avatar
Florent Chehab committed
179
180
181
182
183
184
185
186
187
    # # Sqlite
    # 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
188
189
190
191
192
193
    # Static files (CSS, JavaScript, Images)
    # https://docs.djangoproject.com/en/2.0/howto/static-files/

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

194

Florent Chehab's avatar
Florent Chehab committed
195
196
197
198
else:
    # We should be on heroku server
    print("You are running in production mode")
    django_heroku.settings(locals())
Florent Chehab's avatar
Florent Chehab committed
199
200
201
202
    DEBUG = True  # TODO CHANGE TO FALSE BEFORE GOING IN REAL PRODUCTION

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'