· 5 years ago · May 09, 2020, 08:56 AM
1"""
2Django settings for purbeurre project.
3
4Generated by 'django-admin startproject' using Django 2.2.1.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/2.2/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/2.2/ref/settings/
11"""
12
13import os
14
15# Third party import
16import dj_database_url
17from dotenv import load_dotenv
18
19dotenv_path = os.path.join(os.path.dirname(__file__), '.env')
20load_dotenv(dotenv_path)
21
22# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
23BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
24
25# Quick-start development settings - unsuitable for production
26# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/
27
28# SECURITY WARNING: keep the secret key used in production secret!
29SECRET_KEY = os.environ.get("SECRET_KEY")
30
31ALLOWED_HOSTS = ['127.0.0.1', 'purbeurre-coa.herokuapp.com']
32
33# Application definition
34
35INSTALLED_APPS = [
36 'django.contrib.admin',
37 'django.contrib.auth',
38 'django.contrib.contenttypes',
39 'django.contrib.sessions',
40 'django.contrib.messages',
41 'django.contrib.staticfiles',
42 'django.contrib.sites',
43 # Third party
44 'allauth',
45 'allauth.account',
46 'allauth.socialaccount',
47 # Local
48 'core.apps.CoreConfig',
49 'user.apps.UserConfig',
50 'product.apps.ProductConfig',
51]
52
53MIDDLEWARE = [
54 'django.middleware.security.SecurityMiddleware',
55 'whitenoise.middleware.WhiteNoiseMiddleware',
56 'django.contrib.sessions.middleware.SessionMiddleware',
57 'django.middleware.common.CommonMiddleware',
58 'django.middleware.csrf.CsrfViewMiddleware',
59 'django.contrib.auth.middleware.AuthenticationMiddleware',
60 'django.contrib.messages.middleware.MessageMiddleware',
61 'django.middleware.clickjacking.XFrameOptionsMiddleware',
62]
63
64ROOT_URLCONF = 'purbeurre.urls'
65
66TEMPLATES = [
67 {
68 'BACKEND': 'django.template.backends.django.DjangoTemplates',
69 'DIRS': [os.path.join(BASE_DIR, 'templates')],
70 'APP_DIRS': True,
71 'OPTIONS': {
72 'context_processors': [
73 'django.template.context_processors.debug',
74 'django.template.context_processors.request',
75 'django.contrib.auth.context_processors.auth',
76 'django.contrib.messages.context_processors.messages',
77 ],
78 },
79 },
80]
81
82WSGI_APPLICATION = 'purbeurre.wsgi.application'
83
84# Database
85# https://docs.djangoproject.com/en/2.2/ref/settings/#databases
86
87DATABASES = {
88 'default': {
89 'ENGINE': 'django.db.backends.postgresql_psycopg2',
90 'NAME': os.environ.get('DB_NAME'),
91 'USER': os.environ.get('DB_USERNAME'),
92 'PASSWORD': os.environ.get('DB_PASSWORD'),
93 'HOST': '',
94 'PORT': '5432',
95 }
96}
97
98# Password validation
99# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators
100
101AUTH_PASSWORD_VALIDATORS = [
102 {
103 'NAME': 'django.contrib.auth.password_validation'
104 '.UserAttributeSimilarityValidator',
105 },
106 {
107 'NAME': 'django.contrib.auth.password_validation'
108 '.MinimumLengthValidator',
109 },
110 {
111 'NAME': 'django.contrib.auth.password_validation'
112 '.CommonPasswordValidator',
113 },
114 {
115 'NAME': 'django.contrib.auth.password_validation'
116 '.NumericPasswordValidator',
117 },
118]
119
120# Allauth
121# https://django-allauth.readthedocs.io/en/latest/installation.html
122
123SITE_ID = 1
124
125AUTH_USER_MODEL = 'user.CustomUser'
126
127AUTHENTICATION_BACKENDS = (
128 # Needed to login by username in Django admin, regardless of `allauth`
129 'django.contrib.auth.backends.ModelBackend',
130 # `allauth` specific authentication methods, such as login by e-mail
131 'allauth.account.auth_backends.AuthenticationBackend',
132)
133
134EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
135
136# Disable Username
137ACCOUNT_USER_MODEL_USERNAME_FIELD = 'username'
138ACCOUNT_USERNAME_REQUIRED = False
139# Use Email
140ACCOUNT_EMAIL_REQUIRED = True
141ACCOUNT_AUTHENTICATION_METHOD = 'email'
142ACCOUNT_UNIQUE_EMAIL = True
143
144ACCOUNT_SIGNUP_PASSWORD_ENTER_TWICE = True
145ACCOUNT_SESSION_REMEMBER = True
146
147# ACCOUNT_SIGNUP_FORM_CLASS = 'user.forms.SignupForm'
148ACCOUNT_FORMS = {'signup': 'user.forms.CustomSignupForm'}
149
150LOGIN_REDIRECT_URL = 'home'
151ACCOUNT_LOGOUT_REDIRECT_URL = 'home'
152
153# Internationalization
154# https://docs.djangoproject.com/en/2.2/topics/i18n/
155
156LANGUAGE_CODE = 'fr-FR'
157
158TIME_ZONE = 'UTC'
159
160USE_I18N = True
161
162USE_L10N = True
163
164USE_TZ = True
165
166# Static files (CSS, JavaScript, Images)
167# https://docs.djangoproject.com/en/2.2/howto/static-files/
168
169STATIC_URL = '/static/'
170
171# SECURITY WARNING: don't run with debug turned on in production!
172if os.environ.get('ENV') == 'PRODUCTION':
173 DEBUG = False
174
175 # Static files settings
176 PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
177
178 STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
179
180 # Extra places for collectstatic to find static files.
181 STATICFILES_DIRS = (
182 os.path.join(PROJECT_ROOT, 'static'),
183 )
184
185 # Simplified static file serving.
186 # https://warehouse.python.org/project/whitenoise/
187 STATICFILES_STORAGE = \
188 'whitenoise.storage.CompressedManifestStaticFilesStorage'
189
190 db_from_env = dj_database_url.config(conn_max_age=500)
191 DATABASES['default'].update(db_from_env)
192else:
193 DEBUG = True