· 4 years ago · Nov 14, 2020, 11:34 AM
1"""
2Django settings for swd project.
3
4Generated by 'django-admin startproject' using Django 1.11.6.
5
6For more information on this file, see
7https://docs.djangoproject.com/en/1.11/topics/settings/
8
9For the full list of settings and their values, see
10https://docs.djangoproject.com/en/1.11/ref/settings/
11"""
12
13# from .email_info import *
14# from tools.dev_info import SECRET_KEY
15import os
16import django_heroku
17
18from .config import PRODUCTION, DB_NAME, DB_PASSWORD, DB_USER
19
20# SECURITY WARNING: don't run with debug turned on in production!
21DEBUG = True
22PRODUCTION = False
23
24
25# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
26BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
27
28
29if PRODUCTION:
30 ALLOWED_HOSTS = ['augsd-transcript-tool.herokuapp.com',
31 '10.1.2.132', '0.0.0.0', '127.0.0.1']
32else:
33 ALLOWED_HOSTS = ['augsd-transcript-tool.herokuapp.com']
34
35INSTALLED_APPS = [
36 'jet.dashboard',
37 'jet',
38 'django.contrib.admin',
39 'django.contrib.auth',
40 'django.contrib.contenttypes',
41 'django.contrib.sessions',
42 'django.contrib.messages',
43 'django.contrib.staticfiles',
44 'webpack_loader',
45 'main',
46 'tools',
47 'schema',
48 'graphene_django',
49 'rest_framework',
50 'corsheaders',
51 'braces',
52 'import_export',
53]
54
55REST_FRAMEWORK = {
56 'DEFAULT_PERMISSION_CLASSES': (
57 'rest_framework.permissions.IsAuthenticated',
58 ),
59 'DEFAULT_AUTHENTICATION_CLASSES': (
60 'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
61 'rest_framework.authentication.SessionAuthentication',
62 'rest_framework.authentication.BasicAuthentication',
63 ),
64}
65
66CORS_ORIGIN_ALLOW_ALL = True
67
68# during production need to set it to expire after some time
69JWT_VERIFY_EXPIRATION = False
70
71MIDDLEWARE = [
72 'django.middleware.security.SecurityMiddleware',
73 'django.contrib.sessions.middleware.SessionMiddleware',
74 'swd.middleware.JWTMiddleware',
75 'corsheaders.middleware.CorsMiddleware',
76 'django.middleware.common.CommonMiddleware',
77 'django.middleware.csrf.CsrfViewMiddleware',
78 'django.contrib.auth.middleware.AuthenticationMiddleware',
79 'django.contrib.messages.middleware.MessageMiddleware',
80 'django.middleware.clickjacking.XFrameOptionsMiddleware',
81]
82
83if PRODUCTION:
84 AUTHENTICATION_BACKENDS = (
85 'main.auth_backend.LDAPAuthBackend',
86 'django.contrib.auth.backends.ModelBackend',
87 )
88else:
89 AUTHENTICATION_BACKENDS = (
90 'django.contrib.auth.backends.ModelBackend',
91 )
92
93ROOT_URLCONF = 'swd.urls'
94
95TEMPLATES = [
96 {
97 'BACKEND': 'django.template.backends.django.DjangoTemplates',
98 'DIRS': [
99 os.path.join(BASE_DIR, "templates"),
100 ],
101 'APP_DIRS': True,
102 'OPTIONS': {
103 'context_processors': [
104 'django.template.context_processors.debug',
105 'django.template.context_processors.request',
106 'django.contrib.auth.context_processors.auth',
107 'django.contrib.messages.context_processors.messages',
108 ],
109 },
110 },
111]
112
113WSGI_APPLICATION = 'swd.wsgi.application'
114
115
116# Database
117# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
118
119if PRODUCTION:
120 DATABASES = {
121 'default': {
122 'ENGINE': 'django.db.backends.postgresql_psycopg2',
123 'NAME': DB_NAME,
124 'USER': DB_USER,
125 'PASSWORD': DB_PASSWORD,
126 'HOST': '127.0.0.1',
127 'PORT': '5432',
128 }
129 }
130else:
131 DATABASES = {
132 'default': {
133 'ENGINE': 'django.db.backends.sqlite3',
134 'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
135 }
136 }
137
138
139# Password validation
140# https://docs.djangoproject.com/en/1.11/ref/settings/#auth-password-validators
141
142AUTH_PASSWORD_VALIDATORS = [
143 {
144 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
145 },
146 {
147 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
148 },
149 {
150 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
151 },
152 {
153 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
154 },
155]
156
157LANGUAGE_CODE = 'en-us'
158
159TIME_ZONE = 'UTC'
160
161USE_I18N = True
162
163USE_L10N = True
164
165USE_TZ = True
166
167
168# Static files (CSS, JavaScript, Images)
169# https://docs.djangoproject.com/en/1.11/howto/static-files/
170
171STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
172STATIC_URL = '/static/'
173
174MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
175MEDIA_URL = '/media/'
176
177STATICFILES_DIRS = [
178 os.path.join(BASE_DIR, 'assets'),
179]
180
181WEBPACK_LOADER = {
182 'DEFAULT': {
183 'BUNDLE_DIR_NAME': 'bundles/',
184 'STATS_FILE': os.path.join(BASE_DIR, 'webpack-stats.json'),
185 }
186}
187
188LOGIN_URL = '/login'
189
190DATA_UPLOAD_MAX_NUMBER_FIELDS = 5000
191
192
193EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
194EMAIL_HOST = 'smtp.gmail.com'
195EMAIL_PORT = 587
196EMAIL_USE_TLS = True
197EMAIL_HOST_USER = os.environ.get('EMAIL_HOST_USER')
198EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_HOST_PASSWORD')
199
200SALT_IMG = os.environ.get('SALT_IMG')
201SECRET_KEY = os.environ.get('SECRET_KEY')
202
203django_heroku.settings(locals())
204